我正在尝试获取所有日期的日期系列,包括可用日期,查找现有预订,当前代码是这样:
select to_char(generate_series(
min(scheduled_jobs.at),
max(scheduled_jobs.at),
interval '1 day'), 'YYYY-MM-DD') AS "BookingDate", reference,
CASE WHEN (now(),now()) overlaps
(bookings.del_datetime,bookings.col_datetime) THEN 'On Demo'
WHEN now() > bookings.col_datetime THEN 'Complete'
WHEN NOT EXISTS (select
to_char(generate_series(
min(scheduled_jobs.at),
max(scheduled_jobs.at),
interval '1 day'), 'YYYY-MM-DD')) THEN 'Available'
ELSE 'Advanced Booking'
END AS "Booking Status"
from scheduled_jobs
LEFT OUTER JOIN bookings ON scheduled_jobs.jobable_id = bookings."id"
LEFT JOIN dates_table ON to_char(bookings.del_datetime, 'YYYY-MM-DD') =
dates_table.booking_date
where bookings.registrations = 'REG123'
GROUP BY bookings.registrations, bookings.del_datetime,
bookings.col_datetime, bookings.reference
order by 1 ASC
我目前正在获得“完整版”,“演示版”和“高级版”,但还想显示“可用”。得到这个结果
BookingDate |参考|预订状态
2018-08-30 | 123456789 |完成
2018-09-06 | 222222222 |在演示中
2018-09-07 | 222222222 |在演示中
2018-09-08 | 222222222 |在演示中
2018-09-12 | 789789789 |提前预订
2018-09-13 | 789789789 |提前预订
我想显示的是可用的日期,例如:
BookingDate |参考|预订状态
2018-09-06 | 222222222 |在演示中
2018-09-07 | 222222222 |在演示中
2018-09-08 | 222222222 |在演示中
2018-09-09 | ......... |可用
2018-09-10 | ......... |可用
2018-09-11 | ......... |可用
2018-09-12 | 789789789 |提前预订
2018-09-13 | 789789789 |提前预订
非常感谢