Select a random sample of results from a query result

后端 未结 8 771
-上瘾入骨i
-上瘾入骨i 2020-11-30 20:14

This question asks about getting a random(ish) sample of records on SQL Server and the answer was to use TABLESAMPLE. Is there an equivalent in Oracle 10?

8条回答
  •  独厮守ぢ
    2020-11-30 20:37

    Something like this should work:

    SELECT * 
    FROM table_name
    WHERE primary_key IN (SELECT primary_key 
                          FROM
                          (
                            SELECT primary_key, SYS.DBMS_RANDOM.RANDOM 
                            FROM table_name 
                            ORDER BY 2
                          )
                          WHERE rownum <= 10 );
    

提交回复
热议问题