|
I'll try to give some constructive criticism instead of a drive by pot shot. I'm sorry, it's just that the leading commas make my eyes bleed and I really hope the industry moves away from it. On point 3:
What I do is use CTEs to create intermediate columns (with good names) and then a final one creating the final column. It's way more readable. ```sql with intermediate as ( select DATEDIFF(DAY, timeslot_date, CURRENT_DATE()) > 7 as days_7_difference,
DATEDIFF(DAY, timeslot_date, CURRENT_DATE()) >= 29 as days_29_difference,
LAG(overnight_fta_share, 1) OVER (PARTITION BY timeslot_date, timeslot_channel ORDER BY timeslot_activity) as overnight_fta_share_1_lag,
LAG(overnight_fta_share, 2) OVER (PARTITION BY timeslot_date, timeslot_channel ORDER BY timeslot_activity)as overnight_fta_share_2_lag
from timeslot_data)select iff(days_7_difference, overnight_fta_share_1_lag, null) as C7_fta_share,
iff(days_29_difference, overnight_fta_share_2_lag, null) as C28_fta_share
from intermediate
``` |
I apologize in advance and hope you are able to come to grips with how easy it is to read and understand at some point in the near future.