Hive 查询 - 如何比较一个 table 的日期以查看它是否介于另一个 table 的开始和停止时间戳之间?

Hive Query - How to compare a date from one table to see if its in between start and stop timestamp from another table?

下面是我尝试 运行 的查询示例。我需要的是 - 我只想显示来自 trip_3g table 的记录,其中 oil_chng_date 位于 mma table 的开始和停止时间戳之间,对于给定的 VIN id。

SELECT trip_3g.vin, 
       trip_3g.start, 
       trip_3g.oil_flag, 
       trip_3g.oil_chng_date,
       mma.vin,
       mma.start,
       mma.end,
       mma.lifecycle_mode,
       mma.auth_mode   
FROM trip_3g
INNER JOIN mma ON trip_3g.vin = mma.vin
WHERE trip_3g.region = 'NA' AND trip_3g.oil_flag = 1
LIMIT 100;

尝试在您指定的条件下使用 JOIN

SELECT trip_3g.vin,  trip_3g.start,  trip_3g.oil_flag, trip_3g.oil_chng_date,
       mma.vin, mma.start, mma.end, mma.lifecycle_mode, mma.auth_mode   
FROM trip_3g JOIN
     mma
     ON trip_3g.vin = mma.vin AND
        trip_3g.oil_chng_date BETWEEN mma.start and mma.end
WHERE trip_3g.region = 'NA' AND trip_3g.oil_flag = 1
LIMIT 100;
WHERE ... AND DATEDIFF(day, trip_3g.oil_chng_date, mma.start) <= 0 AND DATEDIFF(day, trip_3g.oil_chng_date, mma.end) >= 0;