Select a random sample of results from a query result

后端 未结 8 785
-上瘾入骨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:23

    We were given and assignment to select only two records from the list of agents..i.e 2 random records for each agent over the span of a week etc.... and below is what we got and it works

    with summary as (
    Select Dbms_Random.Random As Ran_Number,
                 colmn1,
                 colm2,
                 colm3
                 Row_Number() Over(Partition By col2 Order By Dbms_Random.Random) As Rank
        From table1, table2
     Where Table1.Id = Table2.Id
     Order By Dbms_Random.Random Asc)
    Select tab1.col2,
                 tab1.col4,
                 tab1.col5,
        From Summary s
     Where s.Rank <= 2;
    

提交回复
热议问题