简体   繁体   English

我的SQL代码没有为我的查询返回任何行

[英]My SQL code returns no rows for my query

im trying to write a query that will display for each of my employee member the total the employee was contracted to work, the number of hours classed as overtime they worked and the total pay received by that employee for the financial year 2015 which should run from 1st of april 2014 to the 31st of march 2015 however my query doesnt return any values. 我试图编写一个查询,以显示每位我的员工成员与之签约的总工作量,归类为加班的小时数以及该雇员在2015财政年度收到的总薪水2014年4月1日至2015年3月31日,但是我的查询未返回任何值。 now i have a table that is called payroll that iis connected to the employee table via a foreign key, and it also has a foreign key to reference the timesheet of the employee. 现在,我有一个称为工资表的表,该表已通过外键连接到员工表,并且还具有一个外键来引用员工的时间表。 i want my output to be something like this: 我希望我的输出是这样的:

END OF YEAR REPORT 年终报告

BALDROY BARD was contracted for 228 hours, earned £2884.5 basic and £1604.25 in OT. BALDROY BARD的合同为228小时,基本工资为2884.5英镑,加时赛为1604.25英镑。 Total earnings were £4488.75 Pension paid was £145.35 总收入为4488.75英镑,支付的养老金为145.35英镑

now i have data inserted to these tables that ensures that this query will return at least one record. 现在,我已将数据插入到这些表中,以确保此查询将至少返回一条记录。

just dont understand why it wont return any records. 只是不明白为什么它不会返回任何记录。 i haven't included "create view" in the code below because i dont want to keep creating the view and deleting it. 我没有在下面的代码中包含“创建视图”,因为我不想继续创建视图并删除它。

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;

Give this a try, that's all I can propose with what you have shown. 试试看,这就是我所建议的全部内容。

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;    

You should really add a SQL fiddle if it doesn't work 如果不起作用,您应该真正添加一个SQL提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM