Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Random Record Selection Problems.
Message
De
15/12/2003 17:56:35
 
 
À
15/12/2003 17:17:44
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00859259
Message ID:
00859353
Vues:
17
Trey, your trick is really nice - short, crisp and elegant - and I fear my article does not do it justice because it devotes so little text to extolling its virtues and so much to a minor problem. ;-)

And the multiplication (or an addition of 0.0000000000000000) is indeed necessary as can be seen by executing
set decimals to 0
select top 10 percent rand(), * ;
   from <whatever> ;
   order by 1
which will select about half of the source records on average (because about half of the RAND() output rounds to 0 and the rest to 1).

P.S.: it seems that the ORDER BY 0 does not work as a tie breaker (I picked this up from a recent UT post but I did not check thoroughly enough). RAND() * 1.0000000000000000 (or RAND() + 0.0000000000000000) will probably not need a whole lot of tie-breaking to be done, but if values straddling the TOP xxx boundary are to be elíminated then it is probably necessary to add a RECNO() column and include it in the ORDER BY clause. This ensures that each record in the result set is actually distinct as far as ORDER BY is concerned and so TOP will work as expected. Sorry again.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform