根据合同工时计算员工的加班工时

根据合同工时计算员工的加班工时

根据员工的个人合同工时计算员工的加班时间、员工加班的百分比以及加班时间超过 10% 的人数。

示例数据在这里:

http://sqlfiddle.com/#!9/a2ba19/2/0

样本数据有:

ID- Employee ID
PROJECT - Project code Employee belongs to
SEGMENT  -  are the projects an employee is working on
SEG_DESC- description of the projects
CONTRact HRS- is the individual contract hrs the employee is hired to do
HOURS   - are the hours an employee has worked in a segment
TEAM- Employee belongs to
END_OF_WEEK - data is collected weekly

我需要 员工加班的百分比 有多少员工加班超过 10%

完成这些计算后,我需要能够在 Power BI 中可视化数据。

我实际上已经在 Power BI 中实现了我需要做的所有事情 - 但是仪表板非常慢,因此不可行。因此,加班计算需要所有已经在 SQL 中发生。 我该怎么做?

请看看它应该是什么样子:

根据合同工时计算员工的加班工时

asd891661428 回答:根据合同工时计算员工的加班工时

查看您想要的输出,似乎您只需要每个团队每个 ID 的时间的简单总和,在这种情况下,以下内容会产生您想要的 结果:

with ot as (
    select *,Sum(hours) over(partition by project,id,team) TimeWorkedPerWeek 
    from workinghours
)
select *,TimeWorkedPerWeek-[contract hrs] OverTimeHours,(TimeWorkedPerWeek)/[CONTRACT HRS]-1 [%Overtime],case when TimeWorkedPerWeek> [CONTRACT HRS]*1.1 then 1 else 0 end [Overtime > 10%]
from ot
order by id,team

DBFiddle example

本文链接:https://www.f2er.com/2962.html

大家都在问