我有以下记录:
name acct_num address city rep primary
DARTMOUTH HITCHCOCK HOSPITAL 1212 MEDICAL CENTER DR LEBANON P Meehan Y
DARTMOUTH HITCHCOCK HOSPITAL 1212 MEDICAL CENTER DR LEBANON P Johnson N
MASSACHUSETTS GENERAL HOSPITAL 891 PO BOX 123 CHARLESTOWN P Morrison N
MASSACHUSETTS GENERAL HOSPITAL 891 PO BOX 123 CHARLESTOWN P McCoy N
MASSACHUSETTS GENERAL HOSPITAL 891 PO BOX 123 CHARLESTOWN P Lorena N
CLINIC PHARMACY CONTROL SUPPLY 282043 1 MEDICAL CENTER DR LEBANON P Sikes N
CLINIC PHARMACY CONTROL SUPPLY 282043 1 MEDICAL CENTER DR LEBANON P Kang Y
CLINIC PHARMACY CONTROL SUPPLY 282043 1 MEDICAL CENTER DR LEBANON P Tolbert N
基本上我需要查询任何没有主要联系人的医院(所有主要='N')。因此,在上述记录中,我需要获得 MASSACHUSETTS GENERAL HOSPITAL,因为所有记录都是 primary='N'。
我试过:
SELECT * FROM `account_prof_affiliation_view` where primary_sf='N' GROUP BY accnt_num
但这只会捕获甚至只有一个主='N'的所有记录。执行此操作的正确 SQL 查询是什么?