小弟正在做一个工资管理系统,其中需要做一个报表统计全年12个月工资所有应发工资的总和,我想把还没有发工资的月份也列出来,并且设置为0;
我些了一个:
ssql = "select substring(YearMonth,6,2) + '月' as Month,Sum(PaySum) as PaySum from Salary where substring(YearMonth,1,4)='" + comboBox1.Text.Trim() + "' group by YearMonth order by YearMonth";
但只能统计已经发放月份的工资。。。。。。。
请各位大虾帮忙啊!!!!!!
------解决方案--------------------
Select 字段xxx
sum(case YearMonth when '1' PaySum else 0 end) '一月',
sum(case YearMonth when '2' then PaySum else 0 end) '二月',
.
.
.
sum(case xxx when xxx' then PaySum else 0 end) '十二月',
from TB_XXX
group by 字段xxx
------解决方案--------------------
不知道你要求的结果是什么?
楼上可以把1到12月份的工资明细统计出来,如果需要求年薪,你再把上面的查询结果SUM一下,就出来,关键是用到CASE语句,设置没发月份工作为零,用的是Oracle语法,不知道LZ用的是什么数据库?
------解决方案--------------------
做一个年月表,从1-12月,与工作表连接即可,2005可以直接用递归查询解决
------解决方案--------------------
- SQL code
select YearMonth,sum(PaySum)from (select YearMonth,PaySum from Salaryunion allselect '01',0 union allselect '02',0 union allselect '03',0 union allselect '04',0 union allselect '05',0 union allselect '06',0 union allselect '07',0 union allselect '08',0 union allselect '09',0 union allselect '10',0 union allselect '11',0 union allselect '12',0) tgroup by YearMonth
代码迷推荐解决方案:软件开发者薪资,http://www.daimami.com/other/1391128.html