Filter Events with Above-Average Ticket Sales
You're helping the events team identify which events are performing well in terms of total revenue.
They want a list of event IDs where the total ticket sales are above the average across all events.
To get this insight, you'll use GROUP BY
and SUM()
to calculate total sales per event, and then apply a HAVING
clause with a subquery to compare each total to the overall average.
Task
From the purchases
table in the event_ticketing.sqlite
database, return:
event_id
Only include events where the total ticket revenue is greater than the average total revenue per event.
How to solve it
Write a SQL query that groups purchases by event_id
, calculates total revenue with SUM(price)
, and filters with HAVING
using a subquery that computes the average total sales.
Want to learn more?
Join CodeFriends Plus membership or enroll in a course to start your journey.