Filter Events with Above-Average Ticket Sales
The events team wants to know which events are performing above average in terms of total ticket revenue.
You’ll use GROUP BY with SUM() to calculate total sales per event, and then apply a HAVING clause containing a subquery to compare each event’s total to the overall average.
This combination of HAVING and subqueries is a common way to find high-performing categories or entities in SQL.
Task
From the purchases table in the event_ticketing.sqlite database, display:
event_id
Include only events whose total ticket revenue is higher than the average total revenue across all events.
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.
Lessons in this chapter · Solve real-world problems with SQL.
- 1. Filter Bookings by Region
- 2. Sort and Limit Recent Reservations
- 3. Use Logical AND/OR to Filter Hotel Data
- 4. Count Transactions by Customer
- 5. Calculate Average Spending per Client
- 6. Filter Customers with High Transaction Totals
- 7. Join Flights with Passengers
- 8. List Passengers with No Reservations
- 9. Find Customers with High-Priced Ticket Purchases
- 10. Filter Events with Above-Average Ticket Sales
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help