select sum(case when [month]=1 then amount else 0 end) as [1月],
sum(case when [month]=2 then amount else 0 end) as [2月],
...
sum(case when [month]=12 then amount else 0 end) as [12月],
[year] as [年份]
from 我的表
group by [year]
sum(case when [month]=2 then amount else 0 end) as [2月],
...
sum(case when [month]=12 then amount else 0 end) as [12月],
[year] as [年份]
from 我的表
group by [year]
,sum(case when month=1 then amount else 0 end) as 一月
,sum(case when month=2 then shishje else 0 end) as 二月
,sum(case when month=3 then shishje else 0 end) as 三月 ,sum(case when month=4 then shishje else 0 end) as 四月 ,sum(case when month=5 then shishje else 0 end) as 五月 ,sum(case when month=6 then shishje else 0 end) as 六月 ,sum(case when month=7 then shishje else 0 end) as 七月 ,sum(case when month=8 then shishje else 0 end) as 八月 ,sum(case when month=9 then shishje else 0 end) as 九月 ,sum(case when month=10 then shishje else 0 end) as 十月 ,sum(case when month=11 then shishje else 0 end) as 十一月 ,sum(case when month=12 then shishje else 0 end) as 十二月
,year as 年份
from tablenam
group by year
order by year
sum(case when month=1 then amount else 0 end) as 一月
,sum(case when month=2 then shishje else 0 end) as 二月
,sum(case when month=3 then shishje else 0 end) as 三月 ,sum(case when month=4 then shishje else 0 end) as 四月 ,sum(case when month=5 then shishje else 0 end) as 五月 ,sum(case when month=6 then shishje else 0 end) as 六月 ,sum(case when month=7 then shishje else 0 end) as 七月 ,sum(case when month=8 then shishje else 0 end) as 八月 ,sum(case when month=9 then shishje else 0 end) as 九月 ,sum(case when month=10 then shishje else 0 end) as 十月 ,sum(case when month=11 then shishje else 0 end) as 十一月 ,sum(case when month=12 then shishje else 0 end) as 十二月
,year as 年份
from tablenam
group by year
order by year
sum(case [month] when 2 then amount else 0 end) as [2月],
...
sum(case [month] when 12 then amount else 0 end) as [12月],
[year] as [年份]
from yourtable
group by [year]
,[1月] =sum(case [month] when 1 then amount else 0 end)
,[2月] =sum(case [month] when 2 then amount else 0 end)
,....
,[12月]=sum(case [month] when 12 then amount else 0 end)
,年月=[year]
from 表
group by [year]
select
,sum(case when month=1 then amount else 0 end) as 一月
,sum(case when month=2 then shishje else 0 end) as 二月
,sum(case when month=3 then shishje else 0 end) as 三月 ,sum(case when month=4 then shishje else 0 end) as 四月 ,sum(case when month=5 then shishje else 0 end) as 五月 ,sum(case when month=6 then shishje else 0 end) as 六月 ,sum(case when month=7 then shishje else 0 end) as 七月 ,sum(case when month=8 then shishje else 0 end) as 八月 ,sum(case when month=9 then shishje else 0 end) as 九月 ,sum(case when month=10 then shishje else 0 end) as 十月 ,sum(case when month=11 then shishje else 0 end) as 十一月 ,sum(case when month=12 then shishje else 0 end) as 十二月
,year as 年份
from tablenam
group by year
order by year
把第一行sum前的逗号去掉