Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Access queries
Message
From
10/11/2005 11:50:48
 
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:
01067222
Views:
14
>Hi Fabio,
>
>Here is a response I got from my colleague. You really deserve the gratitude, not me. We still need to solve the first problem with counting number of distinct doctors and distinct specialties.
>

Understood!
If VFP is made for the "young marmots",
Access is made for the "newborn marmots" ,
and it doesn't support the JOIN with the order of precedence not defined.

TRY THIS:
#DEFINE #DOCTOR_NAME  1
#DEFINE #SPECIALITY_NUMBER 1

SELECT V.Patient_Name,V.Visit_Date,V.Doctor_Name,D.Doctor_Specialty
FROM ((SELECT V.Patient_Name,V.Visit_Date FROM 
	(SELECT DISTINCT V.Patient_Name,V.Visit_Date,Doctors.Doctor_Specialty
	   ((SELECT V.Patient_Name,V.Visit_Date FROM 
		(SELECT DISTINCT Patient_Name,Visit_Date,Doctor_Name FROM Visits) V
	   		GROUP BY Patient_Name,Visit_Date HAVING COUNT(*)>#DOCTOR_NAME) V
		   JOIN Visits ON Visits.Patient_Name = V.Patient_Name AND Visits.Visit_Date = V.Visit_Date)
	JOIN Doctors ON Doctors.Doctor_Name = Visits.Doctor_Name) V
	GROUP BY Patient_Name,Visit_Date HAVING COUNT(*)=#SPECIALITY_NUMBER) 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 
>==================================================================
>The last two were almost perfect. Seems that Access likes parentheses when doing multiple INNER JOINS, so they worked as follows:
>
>
>
>SELECT V.Patient_Name,V.Visit_Date,V.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 MIN(Visits.Doctor_Name)<>MAX(Visits.Doctor_Name)
>            AND MIN(Doctors.Doctor_Specialty)=MAX(Doctors.Doctor_Specialty)) 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
>
>SELECT V.Patient_Name,V.Visit_Date,V.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 MIN(Visits.Doctor_Name)<>MAX(Visits.Doctor_Name)
>            AND MIN(Doctors.Doctor_Specialty)<>MAX(Doctors.Doctor_Specialty)) 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
>
>
>Note the red parentheses.
>
>I have no idea how she expects us to do this in a paper test situation, so wish me luck. I can barely do it with a computer. I’m still working on that count of docots and specialties one. Considering I answered all of the rest, she may get it as is.
>
>
>Thanks for all of your assistance; you have been invaluable.
Previous
Reply
Map
View

Click here to load this message in the networking platform