Hi all!!
I am working on my SQL course and working on the project ’ Calculating Churn Rates’ under ‘ANALYZE REAL DATA WITH SQL’. See the link here: Description of the task
I got to step 3 and it asked me to create a new table with 3 months of data. I wonder why can’t I write my code like this:
WITH months AS (
SELECT *
FROM subscriptions
WHERE subscription_start <= '2017-03-30'
AND subscription_start >= '2017-01-01'
)
The right code is:
WITH months AS
(SELECT
'2017-01-01' as first_day,
'2017-01-31' as last_day
UNION
SELECT
'2017-02-01' as first_day,
'2017-02-28' as last_day
UNION
SELECT
'2017-03-01' as first_day,
'2017-03-30' as last_day
FROM subscriptions
)
It is a simple code and I can just memorize it but I wonder if there is a way to understand it better. Thank you guys so much!!