ORACLE多列中取出数据最大的一条

1.需求说明:

当查询出来的数据存在多条数据时,想按照一定条件排序取出其中一条数据。

2.使用函数:

row_number() over( partition by 分组字段 order by 排序字段 desc)

3.示例:

--根据table_a中的pk_house,pk_customer进行分组,然后根据table_b.billdate进行排序,取出最大billdate的一条数据

select *
from (select table_a.code,
table_a.name,
table_b.billdate,
row_number() over(partition by table_a.pk_house, table_a.pk_customer order by table_b.billdate desc) rn
from table_a
left join table_b
on table_b.pk_table_a = table_a.pk_table_a
where table_a.code = '11111')
where rn = 1

相关推荐
qq_192779873 小时前
高级爬虫技巧:处理JavaScript渲染(Selenium)
jvm·数据库·python
u0109272713 小时前
使用Plotly创建交互式图表
jvm·数据库·python
爱学习的阿磊3 小时前
Python GUI开发:Tkinter入门教程
jvm·数据库·python
tudficdew4 小时前
实战:用Python分析某电商销售数据
jvm·数据库·python
sjjhd6525 小时前
Python日志记录(Logging)最佳实践
jvm·数据库·python
Configure-Handler5 小时前
buildroot System configuration
java·服务器·数据库
2301_821369615 小时前
用Python生成艺术:分形与算法绘图
jvm·数据库·python
电商API_180079052476 小时前
第三方淘宝商品详情 API 全维度调用指南:从技术对接到生产落地
java·大数据·前端·数据库·人工智能·网络爬虫
2401_832131956 小时前
Python单元测试(unittest)实战指南
jvm·数据库·python
打工的小王7 小时前
redis(四)搭建哨兵模式:一主二从三哨兵
数据库·redis·缓存