我想在 2012 年的各个月份为我的员工获取个人工资。这是代码。
SELECT
jd.job_grade,
e.employee_title||'. '|| e.first_name||' '||e.initials||' '||e.surname as FULLNAME,
e.employee_code,
sum(NVL(jan.amount,0)) as JAN_PAY,
sum(NVL(feb.amount,0)) as FEB_PAY,
sum(NVL(mar.amount,0)) as MAR_PAY,
sum(NVL(apr.amount,0)) as APR_PAY,
sum(NVL(may.amount,0)) as MAY_PAY,
sum(NVL(jun.amount,0)) as JUN_PAY,
sum(NVL(jul.amount,0)) as JUL_PAY,
sum(NVL(aug.amount,0)) as AUG_PAY,
sum(NVL(sep.amount,0)) as SEP_PAY,
sum(NVL(oct.amount,0)) as OCT_PAY,
sum(NVL(nov.amount,0)) as NOV_PAY,
sum(NVL(ar.amount,0)) as DEC_PAY/*,
0.05*sum(NVL(ar.amount,0)) as Bonus*/
from (((((((((((((tbl_actual_run ar
JOIN tbl_actual_run JAN ON jan.emp_code=ar.emp_code)
JOIN tbl_actual_run FEB ON feb.emp_code=ar.emp_code)
JOIN tbl_actual_run MAR ON mar.emp_code=ar.emp_code)
JOIN tbl_actual_run APR ON apr.emp_code=ar.emp_code)
JOIN tbl_actual_run MAY ON may.emp_code=ar.emp_code)
JOIN tbl_actual_run JUN ON jun.emp_code=ar.emp_code)
JOIN tbl_actual_run JUL ON jul.emp_code=ar.emp_code)
JOIN tbl_actual_run AUG ON aug.emp_code=ar.emp_code)
JOIN tbl_actual_run SEP ON sep.emp_code=ar.emp_code)
JOIN tbl_actual_run OCT ON oct.emp_code=ar.emp_code)
JOIN tbl_actual_run NOV ON nov.emp_code=ar.emp_code)
JOIN TBL_EMPLOYEE E ON E.EMPLOYEE_CODE=ar.emp_code)
JOIN tbl_job_details jd ON jd.employee_code=ar.emp_code)
where (ar.payroll_date LIKE '%DEC-12%' and ar.ed_code in ('0001','0011','0012','0003'))
and (nov.Payroll_Date LIKE'%NOV-12%'and nov.ed_code in ('0001','0011','0012','0003'))
and (oct.Payroll_Date LIKE'%OCT-12%' and oct.ed_code in ('0001','0011','0012','0003'))
and (sep.Payroll_Date LIKE'%SEP-12%' and oct.ed_code in ('0001','0011','0012','0003'))
and (aug.Payroll_Date LIKE'%AUG-12%' and aug.ed_code in ('0001','0011','0012','0003'))
and (jul.Payroll_Date LIKE'%JUL-12%' and jul.ed_code in ('0001','0011','0012','0003'))
and (jun.Payroll_Date LIKE'%JUN-12%' and jun.ed_code in ('0001','0011','0012','0003'))
and (may.Payroll_Date LIKE'%MAY-12%' and may.ed_code in ('0001','0011','0012','0003'))
and (apr.Payroll_Date LIKE'%APR-12%' and apr.ed_code in ('0001','0011','0012','0003'))
and (mar.Payroll_Date LIKE'%MAR-12%' and mar.ed_code in ('0001','0011','0012','0003'))
and (feb.Payroll_Date LIKE'%FEB-12%' and feb.ed_code in ('0001','0011','0012','0003'))
and (jan.Payroll_Date LIKE'%JAN-12%' and jan.ed_code in ('0001','0011','0012','0003'))
GROUP BY jd.job_grade,e.employee_title,e.first_name,e.initials,e.surname,e.employee_code
order by TO_NUMBER(jd.job_grade) DESC, e.first_name,e.surname
问题是
- 这些数字是累积的,没有反映每个人每个月的收入情况。
- 一年内被雇用或解雇的个人没有出现
笔记:
- TBL_ACTUAL_RUN 是保存所有月薪的地方
- TBL_Employee 是保存所有员工的地方
- TBL_JOB_Details 是保存员工工作信息的地方
有人可以帮忙吗?您的帮助将不胜感激