I had the same question on another post: SELECT an aliased column not yet defined
I think what those of us are finding frustrating is that this is a major gap in the curriculum as that functionality of SQL hasn’t been taught - I’m not even sure if it even gets to that point.
We’ve only learned to SELECT value AS ‘some_name’
Granted the code used in the question is exceptionally neater, we can return the same relevant data by using:
SELECT COUNT(DISTINCT quiz.user_id) AS ‘1- Quiz’,
COUNT(DISTINCT home_try_on.user_id) AS ‘2-home_try_on’,
COUNT(DISTINCT purchase.user_id) AS ‘3-Purchase’
LEFT JOIN purchase
ON quiz.user_id = purchase.user_id
LEFT JOIN home_try_on
ON home_try_on.user_id = quiz.user_id;
At this stage of the curriculum, this is essentially how we are taught to approach it.
I understand (ish) how this works but understanding WHEN to utilize this is where there’s a massive gap.
Now if I work the code backwards entering:
SELECT ‘1-quiz’ AS stage
This changes all the values to ‘1-quiz’ and creates the column “Stage” and goes on for what seems like… ever.
But what is ‘1-quiz’ pulling it’s original info from? As in, what is it selecting if it wasn’t ‘1-quiz’? What is the “value” from which we are pulling the data? It looks like it’s just made up.
Is it effectively like saying:
SELECT * AS stage
FROM quiz; ?
Does that make sense?
Apologies for jumping on this forum post - feel free to respond on my original post.