Posted by Luming, Nov. 29, 2021, 3:04 p.m.
SQL 141
Hi Leon,
I have gone through your lectures of Outer Joins and still feels like I am a bit confuse about the difference between putting something in the 'on' clause and in the 'where 'clause. For example,
WITH daily_revenue AS
(SELECT D.date,
SUM(CASE WHEN total_amt IS NOT NULL THEN total_amt ELSE 0 END) AS daily_revenue
FROM dates D
LEFT JOIN food_order fo
ON DATE(fo.created_at)=D.date AND restaurant_id =100011
WHERE D.date >='2021-08-01' AND D.date <='2021-08-31'
GROUP BY 1
)
SELECT date,
SUM(daily_revenue)OVER(ORDER BY date)AS cumulative_daily_rev
FROM daily_revenue
My question here is why restaurant_id =100011 has to be in the 'on' clause? Why I cannot put it in the 'WHERE' clause?
I have gone through your lectures of Outer Joins and still feels like I am a bit confuse about the difference between putting something in the 'on' clause and in the 'where 'clause. For example,
WITH daily_revenue AS
(SELECT D.date,
SUM(CASE WHEN total_amt IS NOT NULL THEN total_amt ELSE 0 END) AS daily_revenue
FROM dates D
LEFT JOIN food_order fo
ON DATE(fo.created_at)=D.date AND restaurant_id =100011
WHERE D.date >='2021-08-01' AND D.date <='2021-08-31'
GROUP BY 1
)
SELECT date,
SUM(daily_revenue)OVER(ORDER BY date)AS cumulative_daily_rev
FROM daily_revenue
My question here is why restaurant_id =100011 has to be in the 'on' clause? Why I cannot put it in the 'WHERE' clause?