[英]Select values from column with more than one values in another cumulus
I have table X with 2 columns : ID , name 我的表X有两列:ID,name
I need to select only the names with more than 1 ID (and count how much ID those name has) 我只需要选择ID超过1个的名称(并计算这些名称具有多少ID)
table X 表X
|namme|ID |
------------
|A |1 |
------------
|A |2 |
------------
|B |1 |
------------
|C |1 |
------------
|C |4 |
------------
|C |7 |
------------
from the table bellow the answer will be like: 从下面的表格中,答案将是:
|namme|ID Count|
----------------
|A |2 |
----------------
|C |3 |
----------------
name A has 2 IDs 名称A有2个ID
name C has 3 IDs 名称C有3个ID
Try, like: 尝试,例如:
SELECT Name
,COUNT(ID)
FROM Xtable
GROUP BY Name
HAVING COUNT(ID) > 1
use aggregate function count()
使用聚合函数
count()
select name,count(*) as cnt from table group by name
having count(*)>1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.