Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Randomly select n unique codes from 5mln table
Message
De
09/11/2001 11:26:52
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
 
 
À
08/11/2001 13:18:01
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00579211
Message ID:
00579693
Vues:
22
>>Hi everybody,
>>
>>How can I randomly select n (110) codes from some huge table, so these codes would be unique? I'm trying to create a test case now...
>
>
>*   Assumes V. 7 for RW cursor, but can emulate in prev versions.
>
>SELECT cCodes, .F. AS lSelected ;
>   FROM BigTable ;
>   INTO CURSOR UniqueCodes readwrite ;
>   GROUP BY cCodes
>
>lnCodes = _Tally
>
>SELECT UniqueCodes
>
>*  This approach to using RAND() will give randomized numbers, but
>*  the same sequence each time it is run (this is helpful for testing
>*  to determine that changes in execution speed are due to algorithm
>*  changes rather than the distribution of the values).
>
>*  If you want a different series between runs, you can issue a
>*  preliminary call to RAND (-1) which will seed with a value
>*  from the system time clock. For that, uncomment the line below
>
>*  = RAND (-1)
>
>lnSelected = 0
>DO WHILE lnSelected < 110
>   GO lnCodes * RAND () + 1
>   IF NOT lSelected
>       REPLACE lSelected WITH .T.
>       lnSelected = lnSelected + 1
>   ENDIF
>ENDFOR
>
>SELECT cCodes ;
>   FROM UniqueCodes ;
>   WHERE lSelected ;
>   INTO CURSOR SelectedCodes
>
>
I'd rather create cursor SelectedCodes and insert records into it from within the Do While lnSelected<110 loop, so you wouldn't have to run a select against a long table in the end. But other than that, this seems to be the ticket.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform