Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
nanarose
Starting Member
2 Posts |
Posted - 2011-03-09 : 12:27:29
|
Hi everyone, I have a question about sentence NEWID() in T-SQL, specifically using it's used with ORDER BY. I need to generate a random sample, and I know I can use ORDER BY NEWID() to accomplish that. Is that correct? Also, I'd like to prove that the random sample generated through this sentence belongs to a uniform distribution. Hope you can help me, many thanks. |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
nanarose
Starting Member
2 Posts |
Posted - 2011-03-09 : 12:58:14
|
Hi, thanks for the response. With uniform distribution I mean: if the ORDER BY NEWID() sentence (used with the TOP n) produces intervals such that every item in each interval has the same probability to belong to the sample.Actually, all I know is that NEWID() assigns a GUID to each row, depending on the IP address and system time, but I don't know what happens next when you add the ORDER and finally the TOP n. Technically, how does it generates the sample?SELECT TOP n FROM table ORDER BY NEWID() Thank you all! |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|
|
|