如何获取过去 5 年中每个日期的当前员工人数
How to get current employee counts as of every date in the last 5 years
--PL/SQL
我想要两个结果列。一列是过去 5 年中的每个日期,另一列是每个日期的员工人数。
我在下面有一个查询,您可以在其中输入一个日期作为参数,它会告诉您该日期有多少人受雇,但我不知道如何推断它以实现我的上述目标。实现我的目标将使参数变得不必要,所以我希望摆脱它。
请帮忙,我很困惑!
select count(person_id), :EFF_DATE
from
(
select paa.person_id
from apps.per_all_assignments_f paa --employee assignments
,apps.per_assignment_status_types past --assignment statuses
where paa.assignment_status_type_id = past.assignment_status_type_id
and past.user_status in ('Active Assignment','Transitional - Active','Transitional -
Inactive','Sabbatical','Sabbatical 50%')
and :EFF_DATE between paa.effective_start_date and paa.effective_end_date
group by paa.person_id
)
如果我没理解错的话,您需要创建一个包含过去 5 年所有日期的 日历,然后将其加入您当前在该查询中使用的表。
类似这样的东西(未经测试,因为我没有你的表格或数据):
WITH
calendar (datum)
AS
-- last 5 years
( SELECT TRUNC (SYSDATE) - LEVEL + 1
FROM DUAL
CONNECT BY LEVEL <=
TRUNC (SYSDATE) - ADD_MONTHS (TRUNC (SYSDATE), -12 * 5))
SELECT c.datum, COUNT (DISTINCT paa.person_id) cnt
FROM calendar c
JOIN apps.per_all_assignment_f paa
ON c.datum BETWEEN paa.effective_start_date
AND paa.effective_end_date
JOIN apps.per_assignment_status_types past
ON past.assignment_status_type_id = paa.assignment_status_type_id
WHERE past.user_status IN ('Active Assignment',
'Transitional - Active',
'Transitional - Inactive',
'Sabbatical',
'Sabbatical 50%')
GROUP BY c.datum
ORDER BY c.datum;
--PL/SQL
我想要两个结果列。一列是过去 5 年中的每个日期,另一列是每个日期的员工人数。
我在下面有一个查询,您可以在其中输入一个日期作为参数,它会告诉您该日期有多少人受雇,但我不知道如何推断它以实现我的上述目标。实现我的目标将使参数变得不必要,所以我希望摆脱它。
请帮忙,我很困惑!
select count(person_id), :EFF_DATE
from
(
select paa.person_id
from apps.per_all_assignments_f paa --employee assignments
,apps.per_assignment_status_types past --assignment statuses
where paa.assignment_status_type_id = past.assignment_status_type_id
and past.user_status in ('Active Assignment','Transitional - Active','Transitional -
Inactive','Sabbatical','Sabbatical 50%')
and :EFF_DATE between paa.effective_start_date and paa.effective_end_date
group by paa.person_id
)
如果我没理解错的话,您需要创建一个包含过去 5 年所有日期的 日历,然后将其加入您当前在该查询中使用的表。
类似这样的东西(未经测试,因为我没有你的表格或数据):
WITH
calendar (datum)
AS
-- last 5 years
( SELECT TRUNC (SYSDATE) - LEVEL + 1
FROM DUAL
CONNECT BY LEVEL <=
TRUNC (SYSDATE) - ADD_MONTHS (TRUNC (SYSDATE), -12 * 5))
SELECT c.datum, COUNT (DISTINCT paa.person_id) cnt
FROM calendar c
JOIN apps.per_all_assignment_f paa
ON c.datum BETWEEN paa.effective_start_date
AND paa.effective_end_date
JOIN apps.per_assignment_status_types past
ON past.assignment_status_type_id = paa.assignment_status_type_id
WHERE past.user_status IN ('Active Assignment',
'Transitional - Active',
'Transitional - Inactive',
'Sabbatical',
'Sabbatical 50%')
GROUP BY c.datum
ORDER BY c.datum;