I have a university graduate database and would like to extract a random sample of data of around 1000 records.
I want to ensure the sample is representative of the pop
Add a table for storing population.
population
I think it should be like this:
SELECT * FROM ( SELECT id, coursecode, ROW_NUMBER() OVER (PARTITION BY coursecode ORDER BY NEWID()) AS rn FROM degree) t LEFT OUTER JOIN population p ON t.coursecode = p.coursecode WHERE rn <= p.SampleSize