SELECT Patient_Name,Doctor_Count,COUNT(*) Specialty_Count FROM (SELECT DISTINCT V.Patient_Name,V.Doctor_Count,Doctors.Doctor_Specialty ((SELECT V.Patient_Name,COUNT(*) Doctor_Count FROM (SELECT DISTINCT Patient_Name,Doctor_Name FROM Visits) V GROUP BY Patient_Name) V JOIN Visits ON Visits.Patient_Name = V.Patient_Name) JOIN Doctors ON Doctors.Doctor_Name = Visits.Doctor_Name) V GROUP BY Patient_Name,Doctor_Count