Sử dụng:
WITH sample AS (
SELECT t.*,
ROW_NUMBER() OVER (PARTITION BY t.state
ORDER BY NEWID()) AS rank
FROM ZIPCODES t)
SELECT s.*
FROM sample s
WHERE s.rank <= 5
Sử dụng:
WITH sample AS (
SELECT t.*,
ROW_NUMBER() OVER (PARTITION BY t.state
ORDER BY NEWID()) AS rank
FROM ZIPCODES t)
SELECT s.*
FROM sample s
WHERE s.rank <= 5