我正在为董事们制作一份详细的OT报告,直到最后,OT时间正在加倍,但并非对所有员工都如此。在我的查询中,我使用的是Employee 802,并且OT时间是95,但显示为90。我已经尝试了所有已知的信息。感谢我能得到的任何帮助!
USE munprod
select
pr_employee_master.a_location_primary [Dept Code], pr_employee_master.a_location_p_desc as Dept,
pr_employee_master.a_employee_number [Emp Number],
CONCAT(pr_employee_master.a_name_last, ', ',pr_employee_master.a_name_first)[Employee Name],
pr_employee_master.a_job_class_desc [Job Desc],
sum(pr_earn_history.eh_hours_worked) [OT Hours],
sum(pr_earn_history.eh_total_amount) [Total OT Amount],
max(pr_base_pay.a_salary_annual) [Annual_Salary]
from pr_employee_master, pr_earn_history, pr_base_pay
where pr_employee_master.a_employee_number = pr_earn_history.a_employee_number
and pr_employee_master.a_employee_number = pr_base_pay.a_employee_number
and pr_earn_history.a_pay_type in ('200','201') and eh_end_date between '2018-04-01' and '2018-06-30'
and pr_employee_master.a_employee_number = '802'
group by
pr_employee_master.a_location_primary, pr_employee_master.a_location_p_desc,
pr_employee_master.a_employee_number, pr_employee_master.a_name_last,
pr_employee_master.a_name_first, pr_employee_master.a_location_p_short,
pr_employee_master.a_job_class_desc
答案 0 :(得分:0)
使用WHERE
格式(CROSS JOIN
子句中的逗号)时,您需要在FROM
子句中更加明确
尝试一下,让我知道它是否有效。更好的解决方案
FROM pr_employee_master, pr_earn_history, pr_base_pay
WHERE
pr_employee_master.a_employee_number = pr_earn_history.a_employee_number
AND pr_employee_master.a_employee_number = pr_base_pay.a_employee_number
AND pr_earn_history.a_employee_number = pr_base_pay.a_employee_number -- Added*.
AND pr_earn_history.a_pay_type in ('200','201') and eh_end_date between '2018-04-01' AND '2018-06-30'
AND pr_employee_master.a_employee_number = '802'
您的WHERE
子句的一种更好的格式,其作用与以上所述相同。
FROM pr_employee_master as master
INNER JOIN pr_earn_history as histroy
ON master.a_employee_number = histroy.a_employee_number
INNER JOIN pr_base_pay as base
ON base.a_employee_number = history.a_employee_number
WHERE
pr_earn_history.a_pay_type in ('200','201') and eh_end_date between '2018-04-01' and '2018-06-30'
AND pr_employee_master.a_employee_number = '802'