工资统计的问题 (50分)

M

mhtan

Unregistered / Unconfirmed
GUEST, unregistred user!
我的工资表:
部门,月份,各工资项目……
现在要进行部门年业绩统计, 比如要把基本工资1-12月情况统计出来
————————————————
部门 1月 2月 ……12月 合计
……各部门情况
合计 ——各列的合计
————————————————
我的想法是
select dep,sum(a1.jbgz),sum(a2.jbgz)……sum(a12.jbgz)
from (select jbgz from table where mon=1 ) as a1,
(select jbgz from table where mon=2) as a2……
很烦而且还不行,不知道哪里写错了,请问富翁有什么更好的方法?
 
我在sqlserver上找到笨方法
select e_dep,
sum(case when w_month='1' then jbgz else 0 end) as a1,
sum(case when w_month='2' then jbgz else 0 end) as a2,
sum(case when w_month='3' then jbgz else 0 end) as a3,
sum(case when w_month='4' then jbgz else 0 end) as a4,
sum(case when w_month='5' then jbgz else 0 end) as a5,
sum(case when w_month='6' then jbgz else 0 end) as a6,
sum(case when w_month='7' then jbgz else 0 end) as a7,
sum(case when w_month='8' then jbgz else 0 end) as a8,
sum(case when w_month='9' then jbgz else 0 end) as a9,
sum(case when w_month='10' then jbgz else 0 end) as a10,
sum(case when w_month='11' then jbgz else 0 end) as a11,
sum(case when w_month='12' then jbgz else 0 end) as a12,
sum(jbgz) as sum
from employee,salary2002
where w_id=e_id
group by e_dep
但最下面的合计还不知道怎么弄出来?

最惨的是我现在做的东西的数据库是access,好象access不知道case的?是吗?同样的语句老报错
谁告诉怎么转换到可以在access用的sql啊?
 
顶部