1樓:匿名使用者
select name,
sum(case ym when 201001 then amount else 0 end) as 一月,
sum(case ym when 201002 then amount else 0 end) as 二月,
sum(case ym when 201003 then amount else 0 end) as 三月,
sum(case ym when 201004 then amount else 0 end) as 四月,
sum(case ym when 201005 then amount else 0 end) as 五月,
sum(case ym when 201006 then amount else 0 end) as 六月,
....
sum(case ym when 201012 then amount else 0 end) as 十二月
from tab
group by name
2樓:匿名使用者
select name,
[1月]=sum(case when ym='201001' then amount else 0 end),
[2月]=sum(case when ym='201002' then amount else 0 end),
[3月]=sum(case when ym='201003' then amount else 0 end),
[4月]=sum(case when ym='201004' then amount else 0 end),
....
[12月]=sum(case when ym='201012' then amount else 0 end)
from tb
group by name
sql查詢問題,sql查詢問題
select aa01 sum cc02 from aa01inner join bb01 on aa01 bb01 iner join cco1 on bb02 cc02 group by aa01 大概語句就是這樣,bb01和cc01是通過bb02和cc02關聯 select a.aa01,a....
sql連線查詢語句問題,SQL連線查詢語句問題!!!
簡單寫的話,sql語句就是 select top 10 title date from select title date from new union select title date from res union select title date from affiche as tbltit...
sql查詢語句問題
select from 銷售合計 where 出貨單位 like 第一醫院 and 品名 like 蘇靈 or 品名 like 尼莫地平片 也沒啥別的毛病。覺得你這裡沒有必要模糊查詢啊。你不是知道要的是什麼資料嗎,可以將like改成 select from 銷售合計 where 出貨單位 like ...