我想实现给分组追加编号的功能,第一组编号是1,第二组是2,依次类推。
怎么实现?

解决方案 »

  1.   


    Just add rownum as your column in the subquery ..e.g.SQL> select *
      2    from tablename tt;DEPT     SALARY
    ---- ----------
    aa         5000
    bb         3000
    bb         2000
    cc         8000
    cc         7000
    cc         60006 rows selected
    SQL> select zz.*,
      2         rownum
      3    from (
      4          select dept,
      5                 sum(salary) as all_salarys
      6            from tablename tt
      7           group by dept
      8          )zz;DEPT ALL_SALARYS     ROWNUM
    ---- ----------- ----------
    aa          5000          1
    bb          5000          2
    cc         21000          3
      

  2.   

    就是group byGroupID    f1    f2
    1          a    100
    1          a    110
    2          b    150
    2          b    200