Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL syntax for the following
Message
 
 
À
31/07/2007 04:00:36
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:
01244721
Message ID:
01245090
Vues:
26
I think code in the SCAN loop can be shortened to
SCAN
  INSERT INTO OutTable ;
    SELECT TOP 20 PERCENT * FROM MyTable WHERE MyTable.cgroup = UCGroup.cgroup ORDER BY iscore
ENDSCAN
>The help system only states that TOP N is supported in a Non-Correlated Subquery, leaving one to assume that it is not supported in a correlated subquery.
>
>Unfortunately from what I can see you need a correlated subquery to do this in a single SQL statement, but even if that was available I think it would be very inefficient. So in my opinion you would be better off to do something like this:
>
>
>create cursor mytable (cgroup c(1), iscore i)
>SELECT * FROM  mytable INTO CURSOR OutTable READWRITE
>
>FOR X = 1 TO 20
>  cX = CHR(64+X)
>  FOR Y = 1 TO 100
>    INSERT INTO mytable (cgroup,iscore) VALUES (cX,Y)
>  ENDFOR
>ENDFOR
>
>SELECT cgroup FROM mytable GROUP BY cgroup INTO CURSOR UCGroup
>SCAN
>  SELECT TOP 20 PERCENT * FROM MyTable WHERE MyTable.cgroup = UCGroup.cgroup ORDER BY iscore;
>    INTO CURSOR Temp
>  SELECT OutTable
>  APPEND FROM DBF("Temp")
>  USE IN Temp
>  SELECT UCGroup
>ENDSCAN
>USE IN UCGroup
>
>
>In the above example the query runs 20 times, an unoptimized correlated subquery if available would run the query 2000 times. So something like this seems more efficient to me.
>
>
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform