Ahh!.. So close to the end and I don’t know what’s going on!
It’s been going pretty well until the “Learn” explanation seemed a little scant in 8/10. Now at 9/10 I just don’t feel I have enough information. The parentheses were not explained and the graphic is unclear to me. Hanging on to my sense of humor though!
The Instructions say:
SELECT customer_id,
COUNT(subscription_id) as subscriptions
FROM orders
GROUP BY customer_id
Place the above query into a WITH statement using the alias previous_query. Join previous_query with customers and select the following columns:
Admittedly, I’m already lost, but I just went for it anyway:
SELECT customer_id, COUNT(subscription_id) as subscriptions FROM orders GROUP BY customer_id;
WITH previous_query AS (SELECT customers.customer_name, previous_query.subscriptions FROM previous_query JOIN customers ON previous_query.customer_id = customers.customer.id);
Had some problems with this excercise, but here’s my completed one for reference:
with previous_query as (
select customer_id,
count(subscription_id) as subscriptions
from orders
group by customer_id
)
select customers.customer_name,previous_query.subscriptions
from previous_query
join customers
on customers.customer_id = previous_query.customer_id;
the issue i had was on the “ON” portion where both data types need to match. customers.customer_id and previous_query.customer_id are both INT. previously, I was using “ON customers.customer_name = previous_query.subscriptions” which doesn’t work.
The article is interesting. In particular it uses a lot of vocabulary that I don’t believe has been mentioned here – not thus far anyway. Have we talked about CTE or SubQueries at all? The article just hints at how little I know.
Returning this after too long, so maybe I need some review, but I tried this:
WITH previous_query AS (SELECT customers.customer_name, previous_query.subscriptions FROM previous_query JOIN customers ON previous_query.customer_id = customers.customer.id)
SELECT customer_id, COUNT(subscription_id) as subscriptions FROM orders GROUP BY customer_id;
and got the error: “Write the query using the WITH statement”
Ummm…
WITH previous_query AS (
SELECT customer_id,
COUNT(subscription_id) as subscriptions
FROM orders
GROUP BY customer_id)
SELECT customers.customer_name,
previous_query.subscriptions
FROM previous_query
JOIN customers
ON customers.customer_id = previous_query.customer_id;
Look through it to figure out what went wrong, seems your issue is understanding where to put the joins.
I’d say the quickest way to learn/improve on any programming language is to Google your problem and find a stack overflow answer detailing a fix/solution. You’ll pick up the correct terminology really quickly and chances are there isn’t a single programming question you have that hasn’t already been answered there.