要查询得到每组的max(或者min等其他聚合函数)值,并 且得到这个行的其他字段
该如何写呢

解决方案 »

  1.   

    select * from
    (select b.*, rownum rn 
    from (select a.owner,a.table_name,a.num_rows 
    from all_tables a 
    where a.num_rows is not null order by a.num_rows desc)b) c 
    where c.rn=1; 
      

  2.   

    还有种写法,
    select * from t1 a where 最值字段=(select max(最值字段) from t1 where 分组字段=a.分组字段)这种写法可靠么?
      

  3.   


    select * from (
     select * from t
      order by col desc|asc )
     where rownum=1
      

  4.   


    select * from (
    select t.*, row_number(partition by col1 order by col2 desc) rn
    from t)
    where rn=1
      

  5.   

    我想落实下
    select * from t1 a where 最值字段=(select max(最值字段) from t1 where 分组字段=a.分组字段)这种写法可靠么? 
      

  6.   

    1.聚合函数+group by+over(partition by )
    2.聚合函数+group by+over(over by)
    3.聚合函数+group by+substr()
      

  7.   

    用order by的方式比较好理解,也确定只会用一条记录
    而且好移植