中国开发网: 论坛: 发牢骚: 贴子 389684
wynnhjg
不喜欢这样的SQL
select A.TheDate, A.thisMonth, b.formMonth
from (select TO_CHAR(temp.TheDate, 'YYYY-MM') TheDate,
SUM(TO_NUMBER(temp.PJZ)) AS thisMonth
from (select add_months(TJ_RSJ.RQ, -1) TheDate, TJ_RSJ.Pjz
from TJ_RSJ
where trunc(TJ_RSJ.rq, 'mm') = to_date('2006-08', 'yyyy-mm')
and hh = '17025274'
and SJBH = '9010') temp
group by TO_CHAR(temp.TheDate, 'YYYY-MM')) A,
(select 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
where trunc(add_months(TJ_RSJ.RQ, 1), 'mm') =
to_date('2006-08', 'yyyy-mm')
and hh = '17025274'
and SJBH = '9010'
group by TO_CHAR(TJ_RSJ.RQ, 'YYYY-MM')) B

where A.TheDate = B.TheDate

相关信息:


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