我正在尝试使用以下查询计算接下来7天的预订数量。
select calendarDate,
(
select COUNT(*)
FROM isBooked INNER JOIN booking
ON isbooked.BookingID = booking.bookingID
where specificday between booking.startDate and booking.endDate
)
from calendar as specificday
where calendardate between '2015-08-23' and DATE_ADD('2015-08-23', INTERVAL 6 DAY);
我使用的SQL服务器允许使用'作为特定日期'但MySQL没有,我将如何在mysql中重写查询。
答案 0 :(得分:1)
specificday
指的是表,而不是列。您需要WHERE
子句的列名:
select c.calendarDate,
(select COUNT(*)
from isBooked ib INNER JOIN
booking b
ON ib.BookingID = b.bookingID
where c.calendarDate between b.startDate and b.endDate
)
from calendar c
where c.calendardate between '2015-08-23' and DATE_ADD('2015-08-23', INTERVAL 6 DAY);