11 Reorder Rates


#1

Confused on what I'm doing wrong.

select distinct order_id, count(1)
from order_items
group by 1
order by 1;

The question asks:
Let's calculate the reorder ratio for all of SpeedySpoon's products and take a look at the results. Counting the total orders per product is straightforward. We count the distinct order_ids in the order_items table.

Complete the query by passing in the distinct keyword and the order_id column name into the count function

select name, /**/
from order_items
group by 1
order by 1;

Here's a hint on how to use the count function to count distinct columns in a table.


#2

did you manage to get it right? i'm also confused about this...


#3

The question requires that count is passed the order_id column filtered by the distinct keyword.
This code counts the number of items with distinct order ids of the same name whereas your code
counts the number of items with the same order id.

select name, count(distinct order_id)
from order_items
group by 1
order by 1;

#4

Thank you so much for help!


#5

I tried the following code:

select name, count(distinct (order_id))
from order_items
group by 1
order by 1;

It kept returning the table as i wanted it, but kept giving an error.
Why would codecademy do that? Is it a bug?

the code:
select name, count(distinct order_id)
from order_items
group by 1
order by 1;

worked fine, giving the exact same table.


#6

select name, count(distinct (order_id))

@nielsklaassen This is sloppy with the unnecessary parenthesis (brackets). Why they may have returned an error though is similar to the problem I was having when using COUNT(DISTINCT order_id) because it appears to be case sensitive since the output table is looking for a column called count(distinct order_id). I find this a little annoying.


#7

I agree with the sloppiness.

My mistake was thinking DISTINCT worked like some kind of method.
Am I correct in thinking it still does, but the syntax makes it a method which doesnt require brackets?