Re: Selecting random rows from a dataset
- From: "Dejan Sarka" <dejan_please_reply_to_newsgroups.sarka@xxxxxxxxxx>
- Date: Thu, 13 Oct 2005 08:27:12 +0200
Kudos to Steve Kass, i've seen this in one of his posts, I tested it and it
works perfectly:
-- Manual Bernoulli sampling
SELECT RAND(CHECKSUM(NEWID())%1000000000+CustomerKey),*
FROM vTargetMail
WHERE RAND(CHECKSUM(NEWID())%1000000000+CustomerKey)< 0.1
-- 0.1 is the desired probability of choosing a row, change as needed.
GO
--
Dejan Sarka, SQL Server MVP
Mentor
www.SolidQualityLearning.com
"dataGirl" <dataGirl@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:0D2BE4C3-E51D-4D80-A0F6-90BC12553600@xxxxxxxxxxxxxxxx
> Question: If I have created a select statement that returns all possible
> values, can I step through this list using SQL to get a random selection
> of
> 10% of the rows? If so, what commands should I be looking at? The
> closest
> I've came was to get the top 10%. However, I do not want just the top
> 10%, a
> want a random selection. If this can't be done using SQL commands, are
> there
> any suggestions for an alternate method?
>
> Thanks
.
- Prev by Date: Re: Referencing a column from another tables data
- Next by Date: Re: Simple ranking within group
- Previous by thread: Re: create log file for a scrip
- Next by thread: Re: Simple ranking within group
- Index(es):
Relevant Pages
|
|