简体   繁体   中英

Convert this statement to sql query

Display the package number and the number of customers for each package number, only for packages with more than 100 customers.

SELECT pack_num, COUNT(customer) 
FROM table_name 
GROUP BY pack_num
HAVING COUNT(customer) >100

Is this query right? If not please correct me.

To count only the unique costumers you could add a DISTINCT to the COUNT .

SELECT pack_num, COUNT(DISTINCT customer) 
FROM table_name 
GROUP BY pack_num
HAVING COUNT(DISTINCT customer) >100

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM