码迷,mamicode.com
首页 > 其他好文 > 详细

工作笔记

时间:2018-03-22 12:42:07      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:upd   day   post   年龄   年休假   工作   case when   date   where   

1.统计部门员工的学历

SELECT A01.Dept_Code,

SUM(CASE WHEN isnull(A01107,0) in (‘18‘) THEN 1 ELSE 0 END) AS "本科(含以上)",
SUM(CASE WHEN isnull(A01107,0) in (‘16‘) THEN 1 ELSE 0 END) AS "大专",
SUM(CASE WHEN isnull(A01107,0) < ‘16‘ THEN 1 ELSE 0 END) AS "大专及以下"
FROM A01 WHERE (A0191=‘1‘ AND A01.Dept_Code = :部门) GROUP BY A01.Dept_Code

 

2.统计部门员工的司龄

SELECT DISTINCT A01.Dept_Code,
SUM(CASE WHEN isnull(A0152,0) <=0.5 THEN 1 ELSE 0 END) AS "半年以下",
SUM(CASE WHEN isnull(A0152,0) >0.5 and isnull(A0152,0)<=1 THEN 1 ELSE 0 END) AS "半年以上一年以下",
SUM(CASE WHEN isnull(A0152,0) >1 and isnull(A0152,0)<3 THEN 1 ELSE 0 END) AS "一年以上三年以下",
SUM(CASE WHEN isnull(A0152,0) >=3 THEN 1 ELSE 0 END) AS "三年(含)以上" FROM A01 WHERE (A0191=‘1‘ AND A01.DEPT_CODE = :部门) GROUP BY A01.DEPT_CODE

3.统计部门员工的年龄

SELECT DISTINCT A01.Dept_Code,

SUM(CASE WHEN isnull(A01101,0) <30 THEN 1 ELSE 0 END) AS "30周岁以下",
SUM(CASE WHEN isnull(A01101,0) >30 and isnull(A01101,0)<=40 THEN 1 ELSE 0 END) AS "31周岁-40周岁",
SUM(CASE WHEN isnull(A01101,0) >40 and isnull(A01101,0)<=50 THEN 1 ELSE 0 END) AS "41周岁-50周岁",
SUM(CASE WHEN isnull(A01101,0) >50 THEN 1 ELSE 0 END) AS "51周岁以上" FROM A01 WHERE (A0191=‘1‘ AND A01.DEPT_CODE = :部门) GROUP BY A01.DEPT_CODE

4.员工年休假的计算

UPDATE A01 SET A0152=ROUND(datediff(mm,A0141,GETDATE())/12,0) WHERE A0191=‘1‘ AND A0141 IS NOT NULL and day(A0141)<=15         //司龄的计算,小于15号入职
UPDATE A01 SET A0152=ROUND((datediff(mm,A0141,GETDATE())-1)/12,0) WHERE A0191=‘1‘ AND A0141 IS NOT NULL and day(A0141)>15     //大于15号入职

 

工作笔记

标签:upd   day   post   年龄   年休假   工作   case when   date   where   

原文地址:https://www.cnblogs.com/voga/p/8622552.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!