oracle group by用法

前端之家收集整理的这篇文章主要介绍了oracle group by用法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

分组第一个:

SELECT * FROM (SELECT ROW_NUMBER() OVER(PARTITION BY dlr_id ORDER BY user_id DESC) rn,
  u.user_id,u.dlr_id FROM tm_user u where dlr_id='1000001812')
  WHERE rn = 1 ;




select user_id,dlr_id from tm_user tu where tu.rowid in (
select max(rowid) from(
select user_id,dlr_id from tm_user)
group by dlr_id) and dlr_id='1000001812';


Oracle分组排名


情境:只查询某个条件下的N条件记录,如每个分类查询(前)5条 例:(相同商户号只查5条) [sql] view plaincopy select * from (select t.mer_code,t.li_goods_name,t.li_id,dense_rank() over(partition by t.mer_code order by t.li_id) rk from yd_mer_listing t) where rk < 6 说明:rank()的排名是按over()内order by决定的,如果order by的字段值是一样的,那么rank()排名也一样。 优势:如果用in语句,如 … where t.li_id in (select LI_ID from yd_mer_listing m where rownum < 6 and m.mer_code = t.mer_code and m.LI_STATE = '3' )…效率会很低

原文链接:https://www.f2er.com/oracle/210858.html

猜你在找的Oracle相关文章