Skip to content

Issue with the provided solution: Lesson04, Exercise 15 #11

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
DataKimble opened this issue Nov 14, 2022 · 0 comments
Open

Issue with the provided solution: Lesson04, Exercise 15 #11

DataKimble opened this issue Nov 14, 2022 · 0 comments

Comments

@DataKimble
Copy link

The question requests the customer count for states that have at least 1,000 customers who have purchased from ZoomZoom.

The solution provided ([https://github.com/TrainingByPackt/SQL-for-Data-Analytics/blob/master/Lesson04/Exercise15/Exercise15.sql] :

SELECT state, COUNT(*) FROM customers GROUP BY state HAVING COUNT(*)>=1000 ORDER BY state;

This returns the count of customer records, by state, having a customer record count >=1,000. This does not consider whether a customer has purchased or not.

Should the solution not be:

select c.state, count(distinct c.customer_id) from customers c inner join sales s on c.customer_id =s.customer_id group by c.state having count(distinct c.customer_id)>=1000 order by c.state;

To ensure we are only counting, at State level, distinct customers that have purchased a product.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant