sybase 查詢語句(急!) |
尚未結案
|
zhuna
一般會員 發表:26 回覆:39 積分:13 註冊:2003-05-19 發送簡訊給我 |
|
timhuang
尊榮會員 發表:78 回覆:1815 積分:1608 註冊:2002-07-15 發送簡訊給我 |
可以這樣下:
select year, t2.venclass, description, sum(case when month=1 then amt else 0 end) as "1月amt", sum(case when month=2 then amt else 0 end) as "1月amt", sum(case when month=3 then amt else 0 end) as "1月amt", ... sum(case when month=12 then amt else 0 end) as "12月amt", from table1 t1 inner join table2 t2 on t1.vendor=t2.vendor inner join table3 t3 on t2.venclass=t3.venclass group by year, t2.venclass, description order by year, t2.venclass |
zhuna
一般會員 發表:26 回覆:39 積分:13 註冊:2003-05-19 發送簡訊給我 |
引言: 可以這樣下:但是會出現語法錯誤,inner附近的語法錯,是不是在sybase中不能這樣用? 錯誤提示:Incorrect syntax near 'inner'. 互相幫助,共同進步select year, t2.venclass, description, sum(case when month=1 then amt else 0 end) as "1月amt", sum(case when month=2 then amt else 0 end) as "1月amt", sum(case when month=3 then amt else 0 end) as "1月amt", ... sum(case when month=12 then amt else 0 end) as "12月amt", from table1 t1 inner join table2 t2 on t1.vendor=t2.vendor inner join table3 t3 on t2.venclass=t3.venclass group by year, t2.venclass, description order by year, t2.venclass
------
互相幫助,共同進步 |
timhuang
尊榮會員 發表:78 回覆:1815 積分:1608 註冊:2002-07-15 發送簡訊給我 |
[quote]
可以這樣下:
select year, t2.venclass, description, sum(case when month=1 then amt else 0 end) as "1月amt", sum(case when month=2 then amt else 0 end) as "1月amt", sum(case when month=3 then amt else 0 end) as "1月amt", ... sum(case when month=12 then amt else 0 end) as "12月amt", -- 最後一個逗號要拿掉 from table1 t1 inner join table2 t2 on t1.vendor=t2.vendor inner join table3 t3 on t2.venclass=t3.venclass group by year, t2.venclass, description order by year, t2.venclass若還是不行的話就將 from 的後面改為: from table1 t1, table2 t2, table3 t3 where t1.vendor=t2.vendor and t2.venclass=t3.venclass group by year, t2.venclass, description order by year, t2.venclass |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |