mysql - Select where sum less than value -
i working on php/mysql timesheet system, , report want create selects employees have worked less required amount of time between 2 dates. employee's time stored in hours , minutes (int), concerned hours.
the employee table looks like:
id | name 1 | george 2 | fred
the timesheet_entry table:
id | employeeid | hour | date 1 | 1 | 2 | 2013-07-25 2 | 2 | 4 | 2013-07-25 3 | 1 | 3 | 2013-07-25
so if select employees have worked less 5 hours (php variable hrslimit) on 2013-07-25, should return 2 fred, george has worked total of 5 hours on date. have html form user can set variables query.
i have tried:
select employeeid, employeename employee join timesheet_entry tse on tse.tse_employeeid = employeeid , sum(tse.hour) < $hrslimit
i have not worried date yet.
the confusing bit here joining 2 tables. perhaps should select hours , put sum clause @ end in instead?
you need group data , place sum condition in having part of query.
select employee.id, employee.name, date, sum(`hour`) timesheet_entry join employee on timesheet_entry.employeeid=employee.id group timesheet_entry.employeeid,date having sum(`hour`)<$hrslimit
Comments
Post a Comment