我有以下数据库设计:
Users Table: NetworkID, Name, BadgeNo, DepartmentCode
Events Table: ID, Title, Description, Location, StartDateTime, EndDateTime, NumberOfSeats, IsActive
BookingDetails Table: BookingID, EventID, NetworkID
我需要提出一个查询,显示每个事件中的座位数、预订数和剩余(或可用)座位数。我写了一个查询,显示座位数和预订数。现在,我需要找到等于(座位数 - 预订数)的剩余(或可用)座位数。那么你能帮我修改它以找到这个要求吗?
我的查询:
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