中国开发网: 论坛: 发牢骚: 贴子 390774
wynnhjg
日,写出SQL后,放在JAVA里拼,拼错了,不知道错在哪里了.
select temp2.hh,
YH_YH.Hm,
temp2.thedate,
temp2.thismonth,
temp2.formmonth,
abs((temp2.thismonth - temp2.formmonth)) / temp2.formmonth rate
from (select temp1.hh,
TO_CHAR(temp1.sjsj, 'YYYY-MM') thedate,
SUM(TO_NUMBER(temp1.thisMonth)) thismonth,
SUM(TO_NUMBER(temp1.formMonth)) formMonth
from (select add_months(to_date(A.TheDate, 'yyyy-mm'), 1) sjsj,
A.thisMonth,
a.hh,
a.dwdm,
b.formMonth
from (select temp.hh,
temp.dwdm,
TO_CHAR(temp.TheDate, 'YYYY-MM') TheDate,
SUM(TO_NUMBER(temp.PJZ)) AS thisMonth
from (select YH_YH.hh,
YH_YH.hm,
YH_YH.dwdm,
add_months(TJ_RSJ.RQ, -1) TheDate,
TJ_RSJ.Pjz
from TJ_RSJ, YH_YH
where trunc(TJ_RSJ.rq, 'mm') =
to_date('2006-08', 'yyyy-mm')
and YH_YH.Dwdm = '335505'
and YH_YH.hh = TJ_RSJ.hh
and YH_YH.dwdm = TJ_RSJ.dwdm
and SJBH = '9010') temp
group by temp.hh,
temp.dwdm,
TO_CHAR(temp.TheDate, 'YYYY-MM')) A, --A
(select YH_YH.hh,
YH_YH.dwdm,
TO_CHAR(TJ_RSJ.RQ, 'YYYY-MM') TheDate,
SUM(DECODE(TJ_RSJ.SJBH,
'9010',
TO_NUMBER(TJ_RSJ.PJZ),
NULL)) AS formMonth
from TJ_RSJ, YH_YH
where trunc(add_months(TJ_RSJ.RQ, 1), 'mm') =
to_date('2006-08', 'yyyy-mm')
and YH_YH.Dwdm = '335505'
and YH_YH.hh = TJ_RSJ.hh
and YH_YH.dwdm = TJ_RSJ.dwdm
and SJBH = '9010'
group by YH_YH.hh,
YH_YH.dwdm,
TO_CHAR(TJ_RSJ.RQ, 'YYYY-MM')) B

where A.TheDate = B.TheDate
and a.hh = b.hh
and a.dwdm = b.dwdm) temp1
group by temp1.hh, TO_CHAR(temp1.sjsj, 'YYYY-MM')) temp2,
YH_YH
where YH_YH.hh = temp2.hh
and abs((temp2.thismonth - temp2.formmonth)) / temp2.formmonth > 0.8

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录