Skip to content
Advertisement

SQL show available, reserved and cancelled seats

Basically, I need to show the number of reserved , cancelled and available seats for a train.

I have this for the available seats:

In the trainbooking table, I have a column called “status”. Status is either reserved or cancelled. I need to display the reserved and cancelled seats with the available seats, but i’m not sure how to do this.

Example data of the two tables:

Train:

Trainbooking:

Results:

I’m new to SQL so any help would be appreciated – thanks.

Advertisement

Answer

Try the following, here is the demo.

Output:

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement