I have a doctor table with doctor and patient ID's. I want to select 75 patients for each doctor whose insurance date is currently still active. How would I do that?
Doctor Table
Doctor ID
Patient ID
insurance begin date
insurance end date
Select DoctorID, PatientID, BeginDate, EndDate
From DoctorTable D1
Where PatientID IN
(Select TOP 75 PatientID From DoctorTable D2
Where D2.DoctorID = D1.DoctorID
AND BeginDate <= Date() AND EndDate >= Date())
Order by DoctorID, PatientID
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.