Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Access queries
Message
 
 
To
08/11/2005 12:46:52
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01066285
Message ID:
01066523
Views:
12
>>>but i guess you want this:
>>>
>>>SELECT Visits.Patient_Name
>>>, count(DISTINCT Visits.Doctor_Name) AS Number_Of_Doctors,
>>>, count(DISTINCT Doctors.Doctor_Specialty)  AS Number_Of_Specialities
>>>FROM Doctors
>>>inner join Visits on Doctors.Doctor_Name = Visits.Doctor_Name
>>>GROUP BY Visits.Patient_Name;
>>>
>>
>>I think it would work. I don't have Access here at work, have to wait till I get home.
>>
>>Here are two more problems:
>>
>>Find which patients went to two or more doctors with the same specialty on the same day.
>>
>>Find which patients went to two or more doctors with different specialties on the same day.
>>
>>For these two queries we need to return the patient name, the date, the name of each doctor, and the doctor's specialty.
>
>
>>Find which patients went to two or more doctors with the same specialty on the same day.
>
>SELECT V.Patient_Name,V.Visit_Date,D.Doctor_Name,D.Doctor_Specialty
>FROM
>(SELECT Visits.Patient_Name,Visits.Visit_Date
>  FROM Doctors inner join Visits on Doctors.Doctor_Name = Visits.Doctor_Name
>	GROUP BY Visits.Patient_Name,Visits.Visit_Date
>	HAVING count(DISTINCT Visits.Doctor_Name)>=2
>           AND count(DISTINCT Doctors.Doctor_Specialty)=1) X
>  INNER JOIN  Visits V ON X.Patient_Name=V.Patient_Name AND X.Visit_Date=V.Visit_Date
>  INNER JOIN  Doctors D ON D.Doctor_Name = V.Doctor_Name
>
>>
>>Find which patients went to two or more doctors with different specialties on the same day.
>
>SELECT V.Patient_Name,V.Visit_Date,D.Doctor_Name,D.Doctor_Specialty
>FROM
>(SELECT Visits.Patient_Name,Visits.Visit_Date
>  FROM Doctors inner join Visits on Doctors.Doctor_Name = Visits.Doctor_Name
>	GROUP BY Visits.Patient_Name,Visits.Visit_Date
>	HAVING count(DISTINCT Visits.Doctor_Name)>=2
>           AND count(DISTINCT Doctors.Doctor_Specialty)>1) X
>  INNER JOIN  Visits V ON X.Patient_Name=V.Patient_Name AND X.Visit_Date=V.Visit_Date
>  INNER JOIN  Doctors D ON D.Doctor_Name = V.Doctor_Name
>
Thanks a lot, Fabio.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform