简体   繁体   中英

SQL Query for single table, compare table columns values

i have one table (A) which has column caseid and citin , caseid can have same citin , i want a query where i want particular citin which has 2 or more caseid
I tried

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

Can someone help ?

select a.citin, count(a.caseid) 
from A a 
group by a.citin
having count(a.caseid) > 1
select  a.citin , count(a.caseid) from A a group by a.citin 
having count(a.caseid) >= 2;
SELECT a.citin, COUNT(DISTINCT a.caseid)
FROM A a
GROUP BY a.citin
HAVING COUNT(DISTINCT a.caseid) >= 2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM