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 员工姓名
解决方案 »
- 数组转字符串存储后查找数据的性能问题
- sql语句改变字段顺序
- 两个表合并的很有意思的问题!!!
- 请教各位高手:在SQLServer的服务器端,如何通过SQL语句 更改 指定的客户端电脑的注册表信息!
- 问一个批量插入的问题?
- 我就不信无法排序
- 关于软件的路径问题!
- 如何防止一次插入多条重复记录?
- 为什么客户端第一次联SQL server 时说超时,联不上,第二次就可以,关机后重新开机又不可以了.请各位帮帮!
- 关于dts包 ,到时高分相赠!
- 我将text类型的字段有cast函数转为nvarchar字段的时候,只有前面一小部分
- 程序在用户机器上安装时候,如何把已有的数据库文件加进去(用户机安装了MSDE)
表二:员工姓名,月份。SQL:insert into 表二(员工姓名,月份) select 员工姓名,month(实发工资) from 表一如果不改表,我只会写一个ASP页面来实现。
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 发薪日期
group by 员工姓名
j老师太快了,我进来还没有,不想竟占了三楼,绝无抄袭