业务需求:
1.根据加班记录、请假记录(含销假)生成加班请假汇总表;
2.输出字段机关、科室、姓名、加班、休年假、休补休假、外出、事假、病假、婚假、产假、护理假、陪产假、计生假、探亲假、丧假、产检、育儿假、育儿假期、独生子女陪护假、学习假、家长会、因公、其他
需求分析:
1.加班数据:加班明细表 uf_jbmxb_dt1,按月(取开始日期月份)汇总计算加班天数,相关字段 xm,zbxsc,jbkssj
2.请假数据:请假记录表 uf_qjhz ,按月(取开始日期月份)汇总计算请假天数,已销假(0)排除,相关字段:xm,qjksrq,qxjlx,sfxj,ys;
请假类型:外出 补休假 年休假 事假 病假 婚假 产假 护理假 计生假 探亲假 丧假 其他
3.按人-年月拼接加班数据、请假数据得出基础报表。
4.配置表格报表呈现。
5.备注:(1)建模数据只含有部分数据且数据精准算法不同,可能会与标准报表有差异。(2)报表只汇总数据,没有假期失效逻辑。(3)基础报表最小颗粒为月汇总,按开始日期统计。(4)达梦数据库。
SQL输出:
- 加班数据原始数据查看:select xm, bm, zbxsc, jbkssj from uf_jbmxb_dt1
- 加班数据开始日期取年月Left 做字符串截断。select xm, left(jbkssj, 7) as ny, nvl(zbxsc,0) as sc from uf_jbmxb_dt1
- 请假数据原数据查看select xm, qjksrq, qxjlx, sfxj, ys from uf_qjhz
- 请假数据开始日期取年月Left做字符串截断select xm, left(qjksrq, 7) as ny, qxjlx, sfxj, nvl(ys, 0) as sc from uf_qjhz
- 增加过滤条件,排除销假数据
select
xm ,
left(qjksrq, 7) as ny,
qxjlx ,
nvl(ys, 0) as sc
from
uf_qjhz
where
sfxj!=0
or sfxj is null
- 拼接加班数据
select
xm ,
left(qjksrq, 7) as ny,
nvl(qxjlx, 11) as lx,
nvl(ys, 0) as sc
from
uf_qjhz
where
sfxj!=0
or sfxj is null
union all
select
xm ,
left(jbkssj, 7) as ny,
99 as lx,
nvl(zbxsc, 0) as sc
from
uf_jbmxb_dt1
- 按类型(加班、请假类型)横排天数select
xm ,
ny ,
case lx when 99 then sc else 0 end as jb ,
case lx when 0 then sc else 0 end as wc ,
case lx when 1 then sc else 0 end as bxj,
case lx when 2 then sc else 0 end as nxj,
case lx when 3 then sc else 0 end as shj ,
case lx when 4 then sc else 0 end as bj ,
case lx when 5 then sc else 0 end as hj ,
case lx when 6 then sc else 0 end as cj ,
case lx when 7 then sc else 0 end as hlj,
case lx when 8 then sc else 0 end as jsj,
case lx when 9 then sc else 0 end as tqj,
case lx when 10 then sc else 0 end as sj ,
case lx when 11 then sc else 0 end as qt
from
(
select
xm ,
left(qjksrq, 7) as ny,
nvl(qxjlx, 11) as lx,
nvl(ys, 0) as sc
from
uf_qjhz
where
sfxj!=0
or sfxj is null union all select
xm ,
left(jbkssj, 7) as ny,
99 as lx,
nvl(zbxsc, 0) as sc
from
uf_jbmxb_dt1)
- 按人、年月汇总select
xm ,
ny ,
sum(case lx when 99 then sc else 0 end) as jb ,
sum(case lx when 0 then sc else 0 end) as wc ,
sum(case lx when 1 then sc else 0 end) as bxj,
sum(case lx when 2 then sc else 0 end) as nxj,
sum(case lx when 3 then sc else 0 end) as shj ,
sum(case lx when 4 then sc else 0 end) as bj ,
sum(case lx when 5 then sc else 0 end) as hj ,
sum(case lx when 6 then sc else 0 end) as cj ,
sum(case lx when 7 then sc else 0 end) as hlj,
sum(case lx when 8 then sc else 0 end) as jsj,
sum(case lx when 9 then sc else 0 end) as tqj,
sum(case lx when 10 then sc else 0 end) as sj ,
sum(case lx when 11 then sc else 0 end) as qt
from
(
select
xm ,
left(qjksrq, 7) as ny,
nvl(qxjlx, 11) as lx,
nvl(ys, 0) as sc
from
uf_qjhz
where
sfxj!=0
or sfxj is null union all select
xm ,
left(jbkssj, 7) as ny,
99 as lx,
nvl(zbxsc, 0) as sc
from
uf_jbmxb_dt1)
group by
xm,
ny
- 还缺少科室、机关,查询人员卡片,子查询; select
xm,
(
select departmentid from hrmresource where id=t.xm
) as bm,
(
select subcompanyid1 from hrmresource where id=t.xm
) as jg ,
ny ,
sum(case lx when 99 then sc else 0 end) as jb ,
sum(case lx when 0 then sc else 0 end) as wc ,
sum(case lx when 1 then sc else 0 end) as bxj,
sum(case lx when 2 then sc else 0 end) as nxj,
sum(case lx when 3 then sc else 0 end) as shj ,
sum(case lx when 4 then sc else 0 end) as bj ,
sum(case lx when 5 then sc else 0 end) as hj ,
sum(case lx when 6 then sc else 0 end) as cj ,
sum(case lx when 7 then sc else 0 end) as hlj,
sum(case lx when 8 then sc else 0 end) as jsj,
sum(case lx when 9 then sc else 0 end) as tqj,
sum(case lx when 10 then sc else 0 end) as sj ,
sum(case lx when 11 then sc else 0 end) as qt
from
(
select
xm ,
left(qjksrq, 7) as ny,
nvl(qxjlx, 11) as lx,
nvl(ys, 0) as sc
from
uf_qjhz
where
sfxj!=0
or sfxj is null union all select
xm ,
left(jbkssj, 7) as ny,
99 as lx,
nvl(zbxsc, 0) as sc
from
uf_jbmxb_dt1)t
group by
xm,
ny - 创建视图
CREATE OR REPLACE VIEW view_kq_huizongbaobiao AS
表格报表效果