如何一次查詢不同時間條件之總計資料 |
答題得分者是:folkchen
|
kuanll
一般會員 發表:5 回覆:6 積分:2 註冊:2002-09-25 發送簡訊給我 |
|
folkchen
高階會員 發表:9 回覆:232 積分:173 註冊:2003-10-09 發送簡訊給我 |
Select sum(t1.Amt),sum(t2.Amt),sum(t3.Amt),sum(t4.Amt),sum(t5.Amt)
From Table as t1, Table as t2, Table as t3, Table as t4, Table as t5
Where (t1~t5 的 Join Key)
And (t1 的資料篩選)
And (t2 的資料篩選)
And (t3 的資料篩選)
And (t4 的資料篩選)
And (t5 的資料篩選) 限制:Join Key 不能為資料篩選的欄位 若你的資料庫有支援 SubQuery 可以使用以下方法,沒有限制 Select
From (Select (JoinKey...),sum(Amt) as totAmt From Table Where (t1 的資料篩選)) as t1,
And (Select (JoinKey...),sum(Amt) as totAmt From Table Where (t2 的資料篩選)) as t2,
And (Select (JoinKey...),sum(Amt) as totAmt From Table Where (t3 的資料篩選)) as t3,
And (Select (JoinKey...),sum(Amt) as totAmt From Table Where (t4 的資料篩選)) as t4,
And (Select (JoinKey...),sum(Amt) as totAmt From Table Where (t5 的資料篩選)) as t5
Where (t1~t5 的 Join Key) 若以上都不行,可能只有建 View 或 Work Table 的方式了
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |