Quicksight:两个日期之间的计算

Quicksight: Calculation between two dates

我在以下主要领域从事酒店预订工作:

问题是我有每次预订的总晚数,但我想 table 每个日期的总晚数。数据示例:

"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

我如何用新的“stay_date”替换原始数据集的 check_in,该新“stay_date”汇总了同一天入住的所有预订?

可以直接使用 Quicksight 解决,还是我必须对数据库进行不同的查询 (Mysql)?

您需要在 Mysql 上进行不同的查询。您需要使用一个字段 date 创建一个名为 dates 的 table。您需要在此处填写您可能需要报告的所有日期(例如从 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