|
|
发表于 2007/9/17 22:23:37
|
显示全部楼层
不知道是不是完全理解楼主需求,一般系统都有Calendar,可以利用它来都到当月的天数(相同月的Period Code是一样的)生成报表。如果一定要用自然月,试试下面的query(以OPM Transaction Table为例)。
select d.trans_date, sales, production, purchase
from
(
select trunc(trans_date) trans_date, sum(trans_qty) Sales
from ic_tran_pnd
where to_char(sysdate,'YYYY-MON') =to_char(trans_date,'YYYY-MON')
and doc_type = 'OMSO'
group by trunc(trans_date)
) a
,(
select trunc(trans_date) trans_date, sum(trans_qty) Production
from ic_tran_pnd
where to_char(sysdate,'YYYY-MON') =to_char(trans_date,'YYYY-MON')
and doc_type = 'PROD'
group by trunc(trans_date)
) b,
(
select trunc(trans_date) trans_date, sum(trans_qty) Purchase
from ic_tran_pnd
where to_char(sysdate,'YYYY-MON') =to_char(trans_date,'YYYY-MON')
and doc_type = 'PORC'
group by trunc(trans_date)
) c,
(
select distinct trunc(trans_date) trans_date from ic_tran_pnd
where to_char(sysdate,'YYYY-MON') =to_char(trans_date,'YYYY-MON')
) d
where d.trans_date =a.trans_date (+)
and d.trans_date = b.trans_date(+)
and d.trans_date= c.trans_date(+)
order by 1
如果需要期初与期末库存,要再加两个Query连接。 |
|