Oracle分组后取其中一条记录

leon51 2020-02-28 06:05:17
比如下面这张表,我要取出每个产品index最大的记录,SQL应该怎么写?
index最小的呢?谢谢

...全文
1228 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
phuson 2020-03-09
  • 打赏
  • 举报
回复
忘了写表名了 select * from (select product_name,product_subname,row_number()over(partition by product_name order by index desc) px from tb where 条件) A where A.px=1 取最小,反desc改成asc
leon51 2020-03-06
  • 打赏
  • 举报
回复
引用 2 楼 phuson 的回复:
取最大: select * from (select product_name,product_subname,row_number()over(partition by product_name order by index desc) px) A where A.px=1 取最小,反desc改成asc
感谢你的回复。 我没有在
select product_name,product_subname,row_number()over(partition by product_name order by index desc)
中看到表名?如果要加一个条件,比如product_name长度等于1,要怎么改呢?谢谢
phuson 2020-03-02
  • 打赏
  • 举报
回复
取最大: select * from (select product_name,product_subname,row_number()over(partition by product_name order by index desc) px) A where A.px=1 取最小,反desc改成asc
leon51 2020-02-29
  • 打赏
  • 举报
回复
取最大的index结果应该是: A Auf 3 B Bj 2 c Cy 4 取最小的index结果应该是: A A1c 1 B Bg 1 c Ck 1

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧