我有这个查询来表达一组业务规则。为了获得我需要的信息,我尝试加入表本身,但这会带回比表中实际更多的记录。以下是我尝试过的查询。我究竟做错了什么?
SELECT DISTINCT a.rep_id, a.rep_name, count(*) AS 'Single Practitioner'
FROM [SE_Violation_Detection] a inner join [SE_Violation_Detection] b
ON a.rep_id = b.rep_id and a.hcp_cid = b.hcp_cid
group by a.rep_id, a.rep_name
having count(*) >= 2