如何在sql列中显示所有相同的值?

时间:2019-03-08 17:41:52

标签: sql

我有一张桌子Group

group  no -of -win
------ ---
a      3
b      3
c      4

我怎么显示

group
---------
a
b  

作为输出?也就是说,获胜次数相同的组。

3 个答案:

答案 0 :(得分:-1)

使用自我加入

DEMO

select distinct a.group from tablename a
join tablename b where a.group<>b.group and a.noofwin=b.noofwin

输出:

grp
a
b

答案 1 :(得分:-1)

您可以使用EXISTS做到这一点:

select t.groupcolumn from tablename t
where exists (
  select 1 from tablename 
  where 
    groupcolumn <> t.groupcolumn
    noofwins = t.noofwins
)
order by t.noofwins, t.groupcolumn

答案 2 :(得分:-1)

SELECT GroupName
FROM Groups a
WHERE EXISTS(SELECT TOP 1 1 FROM Groups b WHERE b.GroupName <> a.GroupName AND b.Score = a.Score)