Skip to content

Instantly share code, notes, and snippets.

@ecwyne
Created April 3, 2024 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ecwyne/a30d838f16abc8d1844250b17ca4a840 to your computer and use it in GitHub Desktop.
Save ecwyne/a30d838f16abc8d1844250b17ca4a840 to your computer and use it in GitHub Desktop.
Queries to get you started
SELECT
offices.id AS office_id,
offices.abbr AS metro_area,
substr (payments.date, 1, 7) AS mnth,
SUM(payments.amount) AS amount
FROM
payments
INNER JOIN transactions ON transactions.id = payments.transaction_id
INNER JOIN customers ON customers.id = transactions.customer_id
INNER JOIN offices ON offices.id = customers.office_id
WHERE
payments.entered = TRUE
AND payments.date >= '2020-01-01'
GROUP BY
mnth,
office_id;
SELECT
students.state,
substr (payments.date, 1, 7) AS mnth,
SUM(payments.amount) AS amount
FROM
payments
INNER JOIN transactions ON transactions.id = payments.transaction_id
INNER JOIN customers ON customers.id = transactions.customer_id
INNER JOIN offices ON offices.id = customers.office_id
INNER JOIN sc ON sc.customer_id = customers.id
INNER JOIN students ON students.id = sc.student_id
WHERE
payments.entered = TRUE
AND payments.date >= '2020-01-01'
GROUP BY
mnth,
state;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment