報表問題 |
|
sotony
一般會員 發表:1 回覆:0 積分:0 註冊:2002-06-28 發送簡訊給我 |
我要做一個比較的報表, 是這樣的 A)Select ProductName,sum(total) from invoice where date between '2002 3 1' and '2002 3 31' B)Select ProductName,sum(total) from invoice where date between '2001 3 1' and '2001 3 31' A 的結果是 蘋果 10
香蕉 20
橙 30 B 的結果是 蘋果 10
檸檬 50
芒果 10 我要的報表是 3/2002 3/2001 蘋果 10 10
香蕉 20 0
橙 30 0
檸檬 0 50
芒果 0 10 請問高手們,如何達成呢?我初步想法是用Temp DB, 但以後如何排列和怎麼補'0'?
|
delphiwww
資深會員 發表:145 回覆:363 積分:368 註冊:2002-03-13 發送簡訊給我 |
Select ProductName,sum(case when year(date)='2002' then total else 0), sum(case when year(date)='2001' then total else 0)
from invoice
where (date between '2001 3 1' and '2001 3 31') or
(date between '2002 3 1' and '2002 3 31')
group by ProductName
引言: 我要做一個比較的報表, 是這樣的 A)Select ProductName,sum(total) from invoice where date between '2002 3 1' and '2002 3 31' B)Select ProductName,sum(total) from invoice where date between '2001 3 1' and '2001 3 31' A 的結果是 蘋果 10 香蕉 20 橙 30 B 的結果是 蘋果 10 檸檬 50 芒果 10 我要的報表是 3/2002 3/2001 蘋果 10 10 香蕉 20 0 橙 30 0 檸檬 0 50 芒果 0 10 請問高手們,如何達成呢?我初步想法是用Temp DB, 但以後如何排列和怎麼補'0'? |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |