Skip to content

Instantly share code, notes, and snippets.

@webgtx
Created June 21, 2023 03:47
Show Gist options
  • Save webgtx/1c64898571f0bc85d8a16b4c2150840f to your computer and use it in GitHub Desktop.
Save webgtx/1c64898571f0bc85d8a16b4c2150840f to your computer and use it in GitHub Desktop.
Cheatsheet with sql
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