The checkout count changes a wage total
count repetitions before adding money · level 1 of 6
Opening your saved work…
Sign in to save across devices → · Download your guest work before switching accounts.
The checkout count changes a wage total · count repetitions before adding money · level 1 of 6
Loans checked out by each staff member
How many loans has each staff member checked out? Watch the count, then run it. This is the number that will multiply a wage in a moment.
Data: Twin Ports Tool Library.
Why it works, clause by clause
- FROM staff s LEFT JOIN loans l ON l.staff_id = s.id: one row per loan, with the staff member attached; a staff member with no loans keeps one placeholder row.
- COUNT(l.id) per staff member: how many loans each one checked out.
- Read the numbers. Priya has 13. If her wage were on each of those rows, a SUM would count it 13 times.
From the reading: The multiplication trap, paragraph 2
SELECT s.id AS staff_id, s.first_name, COUNT(l.id) AS matching_loans
FROM staff s
LEFT JOIN loans l ON l.staff_id = s.id
GROUP BY s.id, s.first_name
ORDER BY s.id;Query results
Run it to see the result here.Run it to see the result here.
Practice here is evidence for you and your instructor, never a grade. Grades live in Canvas.