Created
June 21, 2023 03:47
-
-
Save webgtx/1c64898571f0bc85d8a16b4c2150840f to your computer and use it in GitHub Desktop.
Cheatsheet with sql
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
SELECT | |
EXTRACT(MONTH FROM payment_date) AS month, | |
COUNT(*) AS total_count, | |
SUM(amount) AS total_amount, | |
COUNT(*) FILTER (WHERE staff_id = 1) AS mike_count, | |
SUM(amount) FILTER (WHERE staff_id = 1) AS mike_amount, | |
COUNT(*) FILTER (WHERE staff_id = 2) AS jon_count, | |
SUM(amount) FILTER (WHERE staff_id = 2) AS jon_amount | |
FROM payment | |
GROUP BY month | |
ORDER BY month; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment