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 15

In 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

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -