Reputation: 45
I have a case statement (part of a much longer query):
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 the first when is commented out, the query runs in about 28 seconds. When I add it in, the query just stalls and times out. I've tried various approaches - adding the date clause in each line, changing it to when l.start_date = current_date
etc and I can't get it to run.
Running Redshift on PopSQL.
Any thoughts? Thanks.
Upvotes: 0
Views: 110
Reputation: 56
Is the order of your when important ?
Because the datediff will be executed for each line but if you put it just before the else, no.
You can also try to work with indexes.
Upvotes: 0