Skip to content

Instantly share code, notes, and snippets.

@Nocks
Created November 6, 2019 02:26
Show Gist options
  • Save Nocks/99ae5a390e565c603893b672b4251f33 to your computer and use it in GitHub Desktop.
Save Nocks/99ae5a390e565c603893b672b4251f33 to your computer and use it in GitHub Desktop.
/*
How much money each staff has processed to date?
*/
SELECT DISTINCT subquery.staff_id, subquery.staff,
SUM(subquery.payment_amount) OVER(PARTITION BY subquery.staff) AS total_amt_received
FROM (
SELECT staff.staff_id staff_id,
CONCAT(staff.first_name, ' ', staff.last_name) AS staff,
payment.amount payment_amount, payment.payment_date payment_date
FROM staff
JOIN payment
ON staff.staff_id = payment.staff_id
) subquery
ORDER BY total_amt_received DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment