简体   繁体   English

将此语句转换为sql查询

[英]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. 显示包裹号和每个包裹号的顾客数量,仅适用于拥有100个以上顾客的包裹。

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 . 要只计算唯一的客户,可以在COUNT上添加DISTINCT

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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