sql - mysql: find max of column where entries have multiple rows -
Sorry for the confused title. I have a column in which there is an hour column that has been done by each employee. I have an employee SSN column and a project ID column on which they are working. I want to find the project on which the most work has been done, however, I can not use a simple maximum because there are several rows in each project, according to which the employee has worked for it for several hours.
Employee Employee Project Time 1 1 20 20 4 30 3 1 15In this example, I will have to return Project 1 below to my code now
select project.pname, works_on.pno, sum (works_on.hours) from works_on add project from work_on.pno = project.pnumber group works_on.pno limit 1
It is close, it gives the total amount of hours worked by a particular project (in this case it shows the project due to the limit 1) if the amount in a maximum () works_o N.hours), then I think it has to be done. However, it gives me an error, so I'm not doing it correctly.
Try to return 1 row with maximum hours:
Work_on join project on works_on at work_on.pno = project.pnumber group, select project.pname, works_on.pno, sum (works_on.hours)
I call it our CRM Made a quick effort on it and it appears to return the desired effect.
Comments
Post a Comment