我有一张表,上面有美国每个邮政编码的记录。为了在地图上显示,我需要为每个州选择X个随机记录。我将如何去做呢?
使用:
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