检索每个的唯一值和计数 [英] Retrieve Unique Values and Counts For Each

查看:97
本文介绍了检索每个的唯一值和计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单的方法来检索列中所有唯一值的列表以及该值出现了多少次?

Is there a simple way to retrieve a list of all unique values in a column, along with how many times that value appeared?

示例数据集:

A
A
A
B
B
C

...将返回:

A  |  3
B  |  2
C  |  1

推荐答案

使用GROUP BY:

Use GROUP BY:

select value, count(*) from table group by value

使用HAVING进一步减少结果,例如仅出现3次以上的值:

Use HAVING to further reduce the results, e.g. only values that occur more than 3 times:

select value, count(*) from table group by value having count(*) > 3

这篇关于检索每个的唯一值和计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆