You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SELECT client_id, name as client_name, COUNT(*) as project_count
FROM projects
GROUP BY client_id
9 results. All had a count of 3 except client_id 6, which had a count of 6.
Find all time entries, and show each one's client name next to it:
SELECT t.*, c.nameas client_name
FROM time_entries t
JOIN projects p
ONp.id=t.project_idJOIN clients c
ONc.id=p.client_idORDER BY client_name
500 results
Find all developers in the "Ohio sheep" group:
SELECT*FROM developers d
JOIN group_assignments ga
ONga.developer_id=d.idJOIN groups g
ONga.group_id=g.idWHEREg.name="Ohio sheep"
3 results
Find the total number of hours worked for each client:
SELECTclients.id, clients.name, count(*) as total_hours
FROM clients
JOIN projects
ONprojects.client_id=clients.idJOIN time_entries te
ONte.project_id=projects.idGROUP BYte.duration
9 results
Find the client for whom Mrs. Lupe Schowalter (the developer) has worked the greatest number of hours:
SELECT clients.*, projects.idas project_id, count(*) as total_hours
FROM clients
JOIN projects
ONprojects.client_id=clients.idJOIN developers
JOIN project_assignments
ONproject_assignments.developer_id=developers.idJOIN time_entries
ONtime_entries.project_id=projects.idWHEREdevelopers.name='Mrs. Lupe Schowalter'GROUP BYtime_entries.durationORDER BY total_hours DESCLIMIT1
List all client names with their project names (multiple rows for one client is fine). Make sure that clients still show up even if they have no projects:
SELECTclients.nameas client_name, projects.nameas project_name
FROM clients
LEFT JOIN projects
ONprojects.client_id=clients.idORDER BYclients.name
33 results
Find all developers who have written no comments:
SELECT developers.*FROM developers
LEFT JOIN comments
ONcomments.developer_id=developers.idWHEREcomments.comment IS NULLORDER BYdevelopers.name