我使用以下主要字段处理酒店预订:
- 预订id
- 入住日期
- 退房日期
- 夜晚:
dateDiff({check-in_date},{check-out_date},"DD")
问题是,我有每次预订的总夜数,但我想有一张表,列出每个日期的总夜。数据示例:
"booking_id","check_in date","check_out date","Nights"
"1010354582","2022-01-01","2022-01-02",1
"1010364988","2022-01-01","2022-01-03",2
"1010366636","2022-01-01","2022-01-03",2
"1010366752","2022-01-01","2022-01-02",1
"1010367996","2022-01-01","2022-01-04",3
我想要的结果是:
"stay_date","Nights"
"2022-01-01",5
"2022-01-02",3
"2022-01-03",1
如何用新的"check_ in"替换原始数据集的check_;stay_ date";同一天入住的所有预订的总和是多少?
它可以直接用Quicksight解决,或者我必须对数据库(Mysql(进行不同的查询?
您需要对Mysql进行不同的查询。您需要创建一个名为dates
的表,其中包含一个字段date
。你需要在那里列出你可能需要报告的所有日子的日期(例如,从2020年到2030年的预填充(。
然后,您需要使用自定义sql查询来进行联接是这样的:
SELECT
dates.date AS stay_date,
COUNT(DISTINCT booking_id) as Nights
FROM
dates LEFT JOIN bookings
ON
dates.date BETWEEN bookings.check_in_date AND bookings.check_out_date - INTERVAL 1 DAY
AND bookings.check_in_date <= bookings.check_out_date - INTERVAL 1 DAY
GROUP BY
dates.date