Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save tu-trinh-scale/ef6172f5c38b7ac783a42f9b3a07ea2e to your computer and use it in GitHub Desktop.

Select an option

Save tu-trinh-scale/ef6172f5c38b7ac783a42f9b3a07ea2e to your computer and use it in GitHub Desktop.
WITH budget_comparison AS (
SELECT
e.event_name,
b.amount as advertisement_budget
FROM Event e
JOIN Budget b ON e.event_id = b.link_to_event
WHERE e.event_name IN ('Yearly Kickoff', 'October Meeting')
AND b.category = 'Advertisement'
AND e.event_date >= '2019-08-01' AND e.event_date <= '2019-12-31'
),
state_expenditures AS (
SELECT
z.state,
SUM(e.cost) as total_approved_expenditure
FROM Member m
JOIN Zip_Code z ON m.zip = z.zip_code
JOIN Expense e ON m.member_id = e.link_to_member
WHERE m.member_id IN (
SELECT link_to_member
FROM Attendance
WHERE link_to_event = 'recggMW2eyCYceNcy'
)
AND e.approved IN (1, 2)
GROUP BY z.state
)
SELECT
ROUND(
(SELECT advertisement_budget FROM budget_comparison WHERE event_name = 'Yearly Kickoff') /
(SELECT advertisement_budget FROM budget_comparison WHERE event_name = 'October Meeting'),
2
) as budget_ratio_times_larger,
(SELECT state FROM state_expenditures ORDER BY total_approved_expenditure DESC LIMIT 1) as highest_expenditure_state
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment