Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL syntax for the following
Message
 
 
To
31/07/2007 04:00:36
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01244721
Message ID:
01245090
Views:
25
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--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform