22,209
社区成员
发帖
与我相关
我的任务
分享
;WITH c1 AS
(
select t.id
from teacher t
LEFT JOIN student s ON t.id=s.teacherid
GROUP BY t.id
HAVING COUNT(t.id)>2
)
SELECT t.*
FROM c1
JOIN teacher t ON c1.id = t.id
select * from teacher a
where id in (select teacherid from student group by teacherid having count(1)>=2)