I have the following database design:
Users Table: NetworkID, Name, BadgeNo, DepartmentCode
Events Table: ID, Title, Description, Location, StartDateTime, EndDateTime, NumberOfSeats, IsActive
BookingDetails Table: BookingID, EventID, NetworkID
I need to come up with a query that shows the number of seats, number of bookings and number of remaining (or availble) seats in each event. I wrote a query that shows the number of seats and number of bookings. Now, I need to find the number of remaining (or available) seats which is equal to (number of seats – number of bookings). So could you please help me in modifying it to find this requirement?
My Query:
SELECT dbo.Events.Title, dbo.Events.Description, dbo.Events.Location, dbo.Events.NumberOfSeats, COUNT(DISTINCT dbo.BookingDetails.NetworkID)
AS [Number of Bookings]
FROM dbo.BookingDetails INNER JOIN
dbo.Users ON dbo.BookingDetails.NetworkID = dbo.Users.NetworkID RIGHT OUTER JOIN
dbo.Events ON dbo.BookingDetails.EventID = dbo.Events.ID
WHERE (dbo.Events.IsActive = 1)
GROUP BY dbo.Events.Title, dbo.Events.Description, dbo.Events.Location, dbo.Events.NumberOfSeats
1 Answer