OK, so I have two tables that I work with - projectand servicesimplified in this way:
project
-------
id PK
name str
service
-------
project_id FK for project
time_start int (timestamp)
time_stop int (timestamp)
One-to-many relationship.
Now I want to return (preferably with a single request) a list of an arbitrary number of projects, sorted by the total amount of time spent on them, which is SUM(time_stop) - SUM(time_start) WHERE project_id =something.
I still have
SELECT project.name
FROM service
LEFT JOIN project ON project.id = service.project_id
LIMIT 100
but I canβt figure out how to do this ORDER BY.
source
share