简体   繁体   中英

SQL - Only include rows that have more than one in class

Im trying to eliminate classes with only 1 pupil

Here is the result i have

结果

Desired Result

在此处输入图片说明

I want only class c to show as it has more than one pupil

I believe its some way of using HAVING but i cant figure it out.

SELECT Pupil, class
FROM school

Using IN

select * 
from school
where class in (select class 
                from school 
                group by class 
                having count(distinct Pupil) > 1)

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