February 27th, 2013, 01:46 PM
Random Samples By Group SQL
So I currently have a database that is tracking requests ([Request Id] - these are unique and numeric) by employee ID (PersonID). Every quarter we have to randomly sample a certain number (say 3) for each individual person to validate.
I am currently using a SQL query that will select the top 3. But I need the three samples to be completely random. Can anyone help me tweak the SQL below to have the selections be RANDOM rather than the top three?
SELECT PersonID, [Request Id] FROM (SELECT [PersonID], [Request Id], (SELECT count(*) FROM [FinSig] as t2
WHERE t2.[PersonID] = t1.[PersonID] and t2.[Request Id] >= t1.[Request Id]) AS RowNum
FROM [FinSig] as t1