根据服务年限显示员工职位
Display employee position based on years of service
我想根据任期长短显示仍然在职(此时未离职)的员工列表,他们的任期基于年数,即:0-5年,6-10年, 11-20 岁,21-30 岁,>30 岁。对于每个任期,还说明其职位。因为1个任期可能有1个以上的职位,所以职位用逗号
出现:服务年限、金额、职位。
我已经尝试过这段代码,但它无法正常工作。
SELECT TIMESTAMPDIFF(year,A.JoinDt,SYSDATE()) AS 'Years Of Service', COUNT(A.EmpCode) AS 'Amount', B.PosName
FROM tblemployee A
INNER JOIN tblposition B ON A.PosCode = B.PosCode
WHERE A.ResignDt IS NULL
GROUP BY B.PosName
这就是我所期待的
服务年限
数量
职位名称
0-5
10
经理
6-10
10
经理
11-20
10
经理
21-30
10
经理
>30
10
经理
有人可以帮助我吗?谢谢
Ps :上面的数量和位置名称,只是输出的一个例子。抱歉,由于与客户的条款和条件,我无法提供输入脚本
**SQL QUERY SHOULD WORK LIKE THIS:
LISTAGG Function may needs to be replaced as it don't support every database but we need to look for alternative function.**
SELECT A.'Years Of Service',A.PosName,LISTAGG(PosName, '; ')
WITHIN GROUP (ORDER BY PosName) as "Aggregated_Pos_name",
A.Amount
FROM (SELECT CASE WHEN (SYSDATE()- a.joindt)/365 <= 5 THEN '0-5'
WHEN (SYSDATE()- a.joindt)/365 BETWEEN 6 AND 10 THEN '6-10'
END AS 'Years Of Service', COUNT(A.EmpCode) AS 'Amount', B.PosName
FROM tblemployee A
INNER JOIN tblposition B ON A.PosCode = B.PosCode
WHERE A.ResignDt IS NULL)A
GROUP BY A.Years of Service;
我想根据任期长短显示仍然在职(此时未离职)的员工列表,他们的任期基于年数,即:0-5年,6-10年, 11-20 岁,21-30 岁,>30 岁。对于每个任期,还说明其职位。因为1个任期可能有1个以上的职位,所以职位用逗号 出现:服务年限、金额、职位。
我已经尝试过这段代码,但它无法正常工作。
SELECT TIMESTAMPDIFF(year,A.JoinDt,SYSDATE()) AS 'Years Of Service', COUNT(A.EmpCode) AS 'Amount', B.PosName
FROM tblemployee A
INNER JOIN tblposition B ON A.PosCode = B.PosCode
WHERE A.ResignDt IS NULL
GROUP BY B.PosName
这就是我所期待的
服务年限 | 数量 | 职位名称 |
---|---|---|
0-5 | 10 | 经理 |
6-10 | 10 | 经理 |
11-20 | 10 | 经理 |
21-30 | 10 | 经理 |
>30 | 10 | 经理 |
有人可以帮助我吗?谢谢
Ps :上面的数量和位置名称,只是输出的一个例子。抱歉,由于与客户的条款和条件,我无法提供输入脚本
**SQL QUERY SHOULD WORK LIKE THIS:
LISTAGG Function may needs to be replaced as it don't support every database but we need to look for alternative function.**
SELECT A.'Years Of Service',A.PosName,LISTAGG(PosName, '; ')
WITHIN GROUP (ORDER BY PosName) as "Aggregated_Pos_name",
A.Amount
FROM (SELECT CASE WHEN (SYSDATE()- a.joindt)/365 <= 5 THEN '0-5'
WHEN (SYSDATE()- a.joindt)/365 BETWEEN 6 AND 10 THEN '6-10'
END AS 'Years Of Service', COUNT(A.EmpCode) AS 'Amount', B.PosName
FROM tblemployee A
INNER JOIN tblposition B ON A.PosCode = B.PosCode
WHERE A.ResignDt IS NULL)A
GROUP BY A.Years of Service;