select 员工姓名,
sum(case month(发薪日期) when 1 then 实发工资 else 0 end) as 一月,
sum(case month(发薪日期) when 2 then 实发工资 else 0 end) as 二月,
........sum(case month(发薪日期) when 12 then 实发工资 else 0 end) as 十二月
from table1
group by 员工姓名

解决方案 »

  1.   

    建议把表二结构改一下,
    表二:员工姓名,月份。SQL:insert into 表二(员工姓名,月份) select 员工姓名,month(实发工资) from 表一如果不改表,我只会写一个ASP页面来实现。
      

  2.   

    select 员工姓名,
           sum(case month(发薪日期) when 1 then 实发工资 else 0 end) as  一月,
           sum(case month(发薪日期) when 2 then 实发工资 else 0 end) as  二月, 
           sum(case month(发薪日期) when 3 then 实发工资 else 0 end) as  三月,
           sum(case month(发薪日期) when 4 then 实发工资 else 0 end) as  四月,
           sum(case month(发薪日期) when 5 then 实发工资 else 0 end) as  五月,
           sum(case month(发薪日期) when 6 then 实发工资 else 0 end) as  六月,
           sum(case month(发薪日期) when 7 then 实发工资 else 0 end) as  七月,
           sum(case month(发薪日期) when 8 then 实发工资 else 0 end) as  八月,
           sum(case month(发薪日期) when 9 then 实发工资 else 0 end) as  九月,
           sum(case month(发薪日期) when 10 then 实发工资 else 0 end) as  十月,
           sum(case month(发薪日期) when 11then 实发工资 else 0 end) as  十一月,
           sum(case month(发薪日期) when 12 then 实发工资 else 0 end) as  十二月 
    from  表一 group by 发薪日期
      

  3.   

    不好意思,打的急:
    group by 员工姓名
    j老师太快了,我进来还没有,不想竟占了三楼,绝无抄袭