This assignment contains a PostgreSQL practice script for a simple football ticket booking system.
The SQL file creates three tables:
Usersfor fan and manager account detailsMatchesfor match information, ticket price, and match statusBookingsfor ticket reservations and payment details
It also adds sample data for users, matches, and bookings, then runs a set of practice queries to demonstrate common SQL operations.
CREATE TABLEandDROP TABLE- Primary key, foreign key, and unique constraints
CHECKconstraints for valid valuesINSERTstatements with sample records- Filtering with
WHERE - Pattern search with
ILIKE COALESCEfor missing valuesINNER JOINandLEFT JOIN- Subquery with
AVG() ORDER BY,LIMIT, andOFFSET
The queries are written to show:
- Champions League matches and ticket prices
- Users whose names match specific patterns
- Booking payment status with a fallback label
- Booking details joined across users and matches
- Users with and without bookings
- Bookings that cost more than the average booking cost
- The second and third highest ticket prices
Run the SQL script in any PostgreSQL environment, such as pgAdmin or a PostgreSQL terminal session.