Using SQL query to find details of customers who ordered > x types of products

后端 未结 2 1715
生来不讨喜
生来不讨喜 2021-01-03 10:10

Please note that I have seen a similar query here, but think my query is different enough to merit a separate question.

Suppose that there is a database with the fol

2条回答
  •  情话喂你
    2021-01-03 11:03

    Isn't that what you are looking for? Seems to be a little bit simpler. Tested it on SQL Server - works fine.

    SELECT customer_name, COUNT(DISTINCT product_ID) as products_count FROM customer_table
    INNER JOIN orders_table ON customer_table.customer_ID = orders_table.customer_ID
    GROUP BY customer_table.customer_ID, customer_name
    HAVING COUNT(DISTINCT product_ID) > 10
    

提交回复
热议问题