如題,我有一個表
column1  column2  column3   column4
1        1        name1     age1
2        2        name2     age2
3        1        name3     age3
4        2        name4     age4
5        1        name5     age5
6        2        name6     age6
...      ...      ...       ...ORCALE數據庫中,如何將column2分組,然后取出每組前50條記錄呢?最好是1條SQL語句完成。

解决方案 »

  1.   

    esay 不过你的前50条纪录的排序条件是哪个
    select aa.*
    from
    (
    select a.*,row_number() over(partition by column2 order by 排序条件)  rn
    from a) aa
    where aa.rn<=50
      

  2.   

    select * from (select col2,col3,col4,row_number() over(partition by col2 order by col1) rn from table_name) where rn < 51
    order by col2,col1
      

  3.   

    呵呵,我的SQL可是错的哦!
    找出来就不抢分了。哈哈!