Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract Random Sample of Transaction Records for Specific Clients

Status
Not open for further replies.

garlanj

Technical User
May 14, 2002
13
GB
I have a table which contains about 43,500 client transaction records for about 2000 different clients. I need to develop some code to extract a random sample of 3 transaction records for each client. Ideally I'd also like to be able to select the clients I sample from - ie for clients 1,4,5,6,22,31 and 32 randomly select 3 transactions - any help would be gratefully received!
 
Do you mean you want a true random selection or do you just mean 'any 3'?
 
It has to satisfy our auditors - so it should be a random sample of 3 transactions for each selected client (ie it can't be the first 3 or the last 3 etc, etc)
 
Use a Top 3 correlated subquery with a sorting clause like this:
ORDER BY Rnd(SomeNumericField)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top