[英]How to filter records based on no of their occurrence in SQL?
I have a table Employer with fields EmployerID and EmployeeID. 我有一个表Employer,其中包含EmployerID和EmployeeID字段。 I need to print all the employeers with more than 2 employees ie count(EmployerID) > 2 when grouped by EmployerID .
当按EmployerID分组时,我需要打印所有雇员超过2名的雇员,即count(EmployerID)> 2。 I am so far able to count the occurrence but not able to filter based on given condition.
到目前为止,我能够计算出发生的次数,但无法根据给定的条件进行过滤。
select EmployerID ,count(EmployerID) from Employer group by EmployerID 从Employer组中按EmployerID选择EmployerID,count(EmployerID)
SELECT EmployerID,COUNT(EmployeeID)
FROM EMPLOYER
GROUP BY EmployerID
HAVING COUNT(EmployeeID) > 2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.