Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Possible in one SELECT command?
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Database:
Visual FoxPro
Divers
Thread ID:
01063783
Message ID:
01063862
Vues:
14
>Fabio
>1) Tested with your final solution, i runs in 4 seconds ( table has 250000 records )...I think the fact i had index on CDate helps.

4 seconds ( too much time !!)

try to add this index:
CLEAR
CREATE CURSOR theTable (OperationID I ,CDate D, CTime C(5), Patient C(30))
INSERT INTO theTable VALUES (345,DATE(2005,10,1),'10:10','Fabio')
INSERT INTO theTable VALUES (367,DATE(2005,10,1),'10:10','Jaime')
INSERT INTO theTable VALUES (399,DATE(2005,10,1),'10:13','Jaime')
INSERT INTO theTable VALUES (444,DATE(2005,10,2),'10:10','Fabio')

INDEX ON OperationID	TAG PK CANDIDATE		
INDEX ON CDate		 TAG IK1
INDEX ON CTime+BINTOC(DOW(CDate),1) TAG IK2	&& add this index

SunDate = DATE(2005,10,1)

SELECT ;
		CTime ;
,	MAX(IIF(DOW(CDate)=1,Patient,SPACE(30)))	AS Sunday	;
,	MAX(IIF(DOW(CDate)=2,Patient,SPACE(30)))	AS Monday   ;
,	MAX(IIF(DOW(CDate)=3,Patient,SPACE(30)))	AS Tuesday  ;
,	MAX(IIF(DOW(CDate)=4,Patient,SPACE(30)))	AS Wednesday;
,	MAX(IIF(DOW(CDate)=5,Patient,SPACE(30)))	AS Thursday	;
,	MAX(IIF(DOW(CDate)=6,Patient,SPACE(30)))	AS Friday	;
,	MAX(IIF(DOW(CDate)=7,Patient,SPACE(30)))	AS Saturday	;
	FROM theTable T ;
	JOIN (SELECT	T.OperationID 	;
	,		COUNT(TB.OperationID)	rowInGroup;
			FROM theTable T ;
			JOIN theTable TB ;
			ON TB.CTime+BINTOC(DOW(TB.CDate),1) == T.CTime+BINTOC(DOW(T.CDate),1);
			AND TB.OperationID <= T.OperationID;
			WHERE T.CDate between m.SunDate AND m.SunDate+3;
		GROUP BY 1) GG ON T.OperationID = GG.OperationID;
	GROUP BY CTime,rowInGroup
>2) In your sample code, if i have at say 9:00 Fabio on Monday and Jaime on Wednesday, they figure in the same row in the result, which is the desired behavior. In real application, this happens only 1% of the cases.
>On the other hand, i don't care, since i now have a cursor with the data i want, i can just SCAN...ENDSCAN and put in the same row whenever applicable.
>
>Thanks for this incredible lesson Fabio, it's pure art what you did :-)
>
>Jaime
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform