Reputation: 410
I have this data set:
I want to produce this:
Here is my query, it's not producing the desired result. I'm trying to count order_ids
and partiton by country. What am I doing wrong?
Note that if I don't include order_id in the GROUP BY, I get the following error order_id is neither present in the group by, nor is it an aggregate function.
SELECT country,
COUNT(repeat_customer_id) repeat_customer,
COUNT(order_id) OVER (PARTITION BY country) total_orders
FROM table
GROUP BY country, order_id
Upvotes: 0
Views: 164
Reputation: 32619
You don't need a window function here, just normal aggregation grouping by country
SELECT country,
COUNT(repeat_customer_id) repeat_customer,
COUNT(*) total_orders
FROM table
GROUP BY country;
Upvotes: 1