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]

解决方案 »

  1.   

    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
      

  2.   

    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
      

  3.   

    select sum(case [month] when 1 then amount else 0 end) as [1月],
     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]
      

  4.   

    select 字段名='值'
    ,[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]
      

  5.   

    回复人: yesterday2000(一笑而过) ( ) 信誉:100  2004-08-06 11:10:00  得分: 0  
     
     
       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  
     
      

  6.   

    不好意思
    把第一行sum前的逗号去掉