select NV.PHG
From Nhanvien NV
Group by NV.phg
Having count(nv.Manv) >= all (select count(NV.MANV from nhanvien nv group by nv.MANV))
我找到了一种更好的方法来找到PHG的“最大计数”NV(在本例中)。我想,我们在做SQL时总是遇到这种情况,我应该有更好的方法。 感谢您阅读:)
答案 0 :(得分:3)
要查找成员数量最多的群组,您可以使用此功能:
SELECT TOP(1) phg, COUNT(*) AS count
FROM Nhanvien
GROUP BY phg
ORDER BY COUNT(*) DESC