我现在正在第三次尝试解决这个问题!
试图显示每个日历日期有多少假期是“活的”。
目前,我有一张带有日历日期的表格和另一张带有假期的表格。我已经使用外部加入了它们,因为没有什么可以加入这两个表。所以这是 4000 个日期 x 200,000 个假期,哎呀!
下面运行的年龄在选定的前10位时,不是前进的道路...(SQL Server)
SELECT top 10
C.CalendarDate,
Case when B.Depart <= C.CalendarDate and vwR.ReturnDate > C.CalendarDate then Count (B.ID) end as 'count'
FROM Calendar C
CROSS JOIN Booking B -- my issue!!
LEFT join vwReturnDate vwR on vwR.ID=B.ID -- bring in the return date
AND C.CalendarDate > '2013-10-01'
AND C.CalendarDate < '2013-10-30' -- narrow to October only
Group by C.CalendarDate, B.ID, B.depart, vwR.ReturnDate
order by c.CalendarDate