不存在子句-查询

时间:2019-05-02 18:23:14

标签: sql data-science presto

我在查询中使用了NOT EXSITS子句,由于我得到的行比预期少,因此要确保它正常工作。

SELECT DISTINCT offer.courier_uuid,
                offer.region_uuid,
                offer.offer_time_local,
                Cast(scores.acceptance_rate AS DECIMAL(5, 3)) AS acceptance_rate
FROM integrated_delivery.trip_offer_fact offer
JOIN integrated_product.driver_score_v2 scores ON offer.courier_uuid = scores.courier_id
AND offer.region_uuid = scores.region_id
AND offer.business_day BETWEEN date '2019-04-04' AND date '2019-04-07'
AND scores.extract_dt = 20190331
AND NOT EXISTS
  (SELECT NULL
   FROM source_cassandra_courier_scheduling.assigned_block_by_id_v2 sched
   JOIN source_cassandra_delivery.region r ON sched.region_id = r.id
   WHERE offer.courier_uuid = sched.courier_id
     AND offer.offer_time_local >= date_parse(date_format(AT_TIMEZONE("start",r.time_zone),'%Y-%m-%d %H:%i:%s'),'%Y-%m-%d %H:%i:%s')
     AND offer.offer_time_local <= date_parse(date_format(AT_TIMEZONE("end",r.time_zone),'%Y-%m-%d %H:%i:%s'),'%Y-%m-%d %H:%i:%s')
     AND element_at(sched.state,-1) = 'ASSIGNED')
ORDER BY 3

我的不存在子句有什么问题吗?我只是问,因为我返回的行比预期的要少。不存在的原因包含时间转换,但我认为这不会影响任何事情。

我正在尝试获取排班表中不存在的所有可能的ID及其报价时间。我想确认我拥有NOT EXISTS子句的方式是否正确,或者是否需要其他东西来正确拉出该棚桌中所有存在或不存在的记录?

0 个答案:

没有答案