有表 a(item,qty,flag),如何查询得如下结果
----------------------------------------------------------------
item totala totalb totalc
----------------------------------------------------------
其中totala为flag='1' qty的和
其中totalb为flag='2' qty的和
其中totalc为flag='3' qty的和
item 为三个的并集,如果哪个存在可以用0填充
----------------------------------------------------------------
item totala totalb totalc
----------------------------------------------------------
其中totala为flag='1' qty的和
其中totalb为flag='2' qty的和
其中totalc为flag='3' qty的和
item 为三个的并集,如果哪个存在可以用0填充
decode(flag, 1, sum(qty), null) totala,
decode(flag, 2, sum(qty), null) totalb,
decode(flag, 3, sum(qty), null) totalc
from a
----------------------------------------------------------------
item totala totalb totalc
----------------------------------------------------------
sysdate为当前日期
其中totala为 startdate<sysdate and enddate<sysdate qty的和
其中totalb为 startdate<sysdate and enddate>sysdate qty的和
其中totalc为 startdate>sysdate and enddate>sysdate qty的和
item 为三个(不同条件)的并集,如果相应的不存在可以在 相应的TOTAL 列填充0