简体   繁体   English

从列中选择值,而在另一个累积中有多个值

[英]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.

相关问题 从单列中的值影响多列的条件中选择多行语句 - Select statement with multiple rows from condition on values in single column affecting more than one column 选择计数超过一个的列的不同值 - Select different values of a column having count more than one 如何从不存在的表中选择具有多个值的列 - how to select a column with more than one values from non-existing table SQL根据另一列中的值从一列中选择值 - SQL select value from one column based on values in another column 从一列中选择共享另一列中的值的值 - Select values from one column which share a value in another column 当同一表的另一列中存在多于1个不同值时,用于从一列中计算不同值的SQL查询 - SQL Query for Counting Distinct Values From One Column When More Than 1 Distinct Value exists in Another Column in the same table 从一列中选择不在另一列中的所有值的有效方法 - Efficient way to select all values from one column not in another column 选择低于另一个值的值-Oracle - Select values lower than another one - Oracle SQL-是否可以从一列中选择所有不同的值,而另一列中的所有值都匹配? - SQL - Is it possible to select all Distinct Values from one column where all values from another column match? select 一列的最大值来自另一字段的多个值 - select max value of one column from multiple values of another field
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM