SQL查询单表,比较表列值

时间:2012-02-17 09:45:26

标签: sql

我有一张表(A),其中有一个列caseid和citin,  caseid可以有相同的citin, 我想要一个查询,我想要特殊的citin,其中有2个或更多的caseid
我试过了

select a.caseid from A as a 
 where citin in (select citin, caseid from A as c  where c.caseid != a.caseid )

有人可以帮忙吗?

3 个答案:

答案 0 :(得分:3)

select a.citin, count(a.caseid) 
from A a 
group by a.citin
having count(a.caseid) > 1

答案 1 :(得分:3)

select  a.citin , count(a.caseid) from A a group by a.citin 
having count(a.caseid) >= 2;

答案 2 :(得分:1)

SELECT a.citin, COUNT(DISTINCT a.caseid)
FROM A a
GROUP BY a.citin
HAVING COUNT(DISTINCT a.caseid) >= 2