感謝您的回答。其實,我發現在PLSQL一些東西,工作地非常好:
select clientname,
max(decode(trim(dow),'MONDAY',totalquantity,0)) Mon,
max(decode(trim(dow),'TUESDAY',totalquantity,0)) Tue,
max(decode(trim(dow),'WEDNESDAY',totalquantity,0)) Wed,
max(decode(trim(dow),'THURSDAY',totalquantity,0)) Thu,
max(decode(trim(dow),'FRIDAY',totalquantity,0)) Fri,
(
max(decode(trim(dow),'MONDAY',totalquantity,0)) +
max(decode(trim(dow),'TUESDAY',totalquantity,0)) +
max(decode(trim(dow),'WEDNESDAY',totalquantity,0)) +
max(decode(trim(dow),'THURSDAY',totalquantity,0)) +
max(decode(trim(dow),'FRIDAY',totalquantity,0))
) TOTAL
from
(
select clientname,
to_char(tradedate, 'DAY') as dow,
sum(quantity) as totalquantity
from ClientTrade a
where a.tradedate >= trunc(sysdate-7,'D')
and a.tradedate <= trunc(sysdate-7,'D') + 4
group by c.clientshortname, tradedate
)
group by clientname
這是有趣的 - 幾乎每一次,人們都忘記給表格命名。在SQL問題中95%一致。 – 2009-04-22 05:31:33
第一個表的名稱總是「a」。 ;) – tpdi 2009-04-22 05:35:40