Https://www.codecademy.com/paths/analyze-data-with-sql/tracks/analyze-data-sql-analyze-real-data/modules/analyze-data-sql-usage-funnels/projects/analyze-data-sql-usage-funnels-with-warby-parker

I am hoping someone help me solve the confusion of the 5 question in project ‘Usage funnel Warby Parker’. The codes from solutions are as followed:

WITH q AS(
SELECT ‘1-quiz’ AS stage, COUNT(DISTINCT user_id)
FROM quiz
),
h AS(
SELECT ‘2-home-try-on’ AS stage,
COUNT(DISTINCT user_id)
FROM home_try_on
),
p AS(
SELECT ‘3-purchase’ AS stage, COUNT(DISTINCT user_id)
FROM purchase)
SELECT *
FROM q
UNION ALL SELECT *
FROM h
UNION ALL SELECT *
FROM p;

My question is, how can we choose ‘1-quiz’, ‘2-home_try_on’ in the WITH…AS… clause? Since the ‘1-quiz’ AS stage doesn’t exist in the databased quiz…Please explain.

Hi @shawnxcai126 - welcome to the forum.

In SQL, when we do something like this:
SELECT 'value' AS column
what we’re doing is creating a new column in the query called column and giving every row in the returned data set the value value.

So, SELECT '1-quiz' AS stage creates a new column - stage - and gives every row the same value of ‘1-quiz’.

Does that make sense? :slight_smile: