Created
November 6, 2019 02:26
-
-
Save Nocks/99ae5a390e565c603893b672b4251f33 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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