SELECT Doctor ID FROM Doctor INNER JOIN Visit ON Doctor ID Visit Docto

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
SELECT Doctor.ID
FROM Doctor INNER JOIN Visit ON Doctor.ID = Visit.Doctor
INNER JOIN Patient ON Patient.ID = Visit.Patient
GROUP BY Doctor.ID
HAVING COUNT(DISTINCT Patient.ID) < 2 * MAX(
SELECT COUNT(DISTINCT P.ID)
FROM Patient AS P INNER JOIN Visit AS V ON P.ID = V.Patient
WHERE V.Doctor = Doctor.ID
GROUP BY P.InsuranceCompany
)