我正在尝试编写一个查询,该查询将显示我的每个员工成员合同工作的总数,他们工作加班的小时数以及该员工在2015财政年度收到的总工资应该从2014年1月1日到2015年3月31日运行但是我的查询不会返回任何值。 现在我有一个名为payroll的表,它通过外键连接到employee表,并且它还有一个外键来引用员工的时间表。我希望我的输出是这样的:
BALDROY BARD签约228小时,基本收入2884.5英镑,OT收入1604.25英镑。 总收入为4488.75英镑,已支付的养老金为145.35英镑
现在我已将数据插入到这些表中,以确保此查询至少返回一条记录。
只是不明白为什么它不会返回任何记录。我没有在下面的代码中包含“创建视图”,因为我不想继续创建视图并将其删除。
SELECT emp_firstname || ' '|| emp_surname || ' was contracted for ' || sum(grade_hours) || ' hours, earned £ ' ||sum(Payroll_standard)|| ' basic and £' ||
sum(Payroll_overtime) || 'in overtime. Total earnings were ' || ( sum(Payroll_overtime) + sum(Payroll_standard)) || ' Pension paid was ' || sum(Payroll_pension) as "END OF YEAR REPORT"
from Funtom_employee left join Funtom_payroll on Payroll_emp = emp_ID
join funtom_grade on grade_id = emp_grade
where payroll_date between '01-apr-14' and '31-mar-15'
group by emp_firstname, emp_surname;
答案 0 :(得分:0)
尝试一下,这就是我能用你所展示的东西提出的所有建议。
SELECT (
emp_firstname || ' ' || emp_surname ||
' was contracted for ' || sum(grade_hours) ||
' hours, earned £' || sum(Payroll_standard) ||
' basic and £' || sum(Payroll_overtime) ||
' in overtime. Total earnings were ' || ( sum(Payroll_overtime) + sum(Payroll_standard)) ||
' Pension paid was ' || sum(Payroll_pension)
) as "END OF YEAR REPORT"
from Funtom_employee
left join Funtom_payroll on Funtom_payroll.Payroll_emp = Funtom_employee.emp_ID
inner join funtom_grade on funtom_grade.grade_id = Funtom_employee.emp_grade
where payroll_date between '01-apr-14' and '31-mar-15'
group by emp_firstname, emp_surname;
如果它不起作用,你应该添加一个SQL小提琴