[英]How do I select distinct columns together with the count of records they have
How do I select distinct columns together with the count of records they have like if i have this data: 如果我有这些数据,如何选择不同的列以及他们喜欢的记录数:
banana
apple
orange
banana
apple
apple
and I want it to display this: 我希望它显示这个:
|banana|2|
|apple |3|
|orange|1|
Make use of aggregate function like COUNT()
and a GROUP BY
clause. 使用像COUNT()
和GROUP BY
子句这样的聚合函数。
SELECT fruitname, COUNT(*) totalCount
FROM tableName
GROUP BY fruitName
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.