将子句添加到case语句会导致查询被拖动



我有一个case语句(更长查询的一部分(:

case 
---when datediff('day',l.start_date,current_date) = 0 then 'Listed Today'
when days_from_start_to_first_inquiry is null then 'No Inquiries Received' 
when days_from_start_to_first_inquiry <= 0.3989 then 'Yes' 
else 'No' end as met_time_to_first_inquiry_goal_yn,

当第一个When被注释掉时,查询将在大约28秒内运行。当我将它添加到中时,查询只是暂停并超时。我尝试了各种方法——在每行中添加date子句,将其更改为when l.start_date = current_date等等,但我无法运行它。

在PopSQL上运行Redshift。

有什么想法吗?谢谢

您的订单何时重要?

因为datediff会为每一行执行,但如果你把它放在其他行之前,则不会。

您也可以尝试使用索引。

最新更新