2016-11-22 39 views

回答

0

有一個built-in query從表中提取樣本。

SELECT * FROM mock TABLESAMPLE(50 PERCENT) 

以下是使用row_number()的替代解決方案。第一數量各行的每個用戶

with numbered as (
    SELECT user, url, row_number() OVER (PARTITION BY user ORDER BY user) as rn FROM mock 
) 

然後,只需要麼選擇奇數或偶數使用pmod行以獲得50%的樣品

SELECT user, url FROM numbered where pmod(rn,2) = 0