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

相关推荐
weixin_4597539419 小时前
golang如何实现Trace上下文传播_golang Trace上下文传播实现思路
jvm·数据库·python
weixin_4440129319 小时前
PHP 中逻辑或(--)运算符的正确使用与条件逻辑重构指南
jvm·数据库·python
iAm_Ike1 天前
Go 中自定义类型与基础类型间的显式类型转换详解
jvm·数据库·python
iuvtsrt1 天前
Golang怎么实现方法集与接口的匹配_Golang如何理解值类型和指针类型实现接口的区别【详解】
jvm·数据库·python
tongluowan0071 天前
MySQL中列数量及长度
数据库·mysql
-liming-1 天前
单片机设计_串口调试工具
数据库·单片机·mongodb
AlfredZhao1 天前
Oracle Deep Data Security (Deep Sec) 初体验
oracle·deep sec·deep data security
鹿角片ljp1 天前
从告警检测到智能研判:SQL 注入研判模型的设计与实践
数据库·sql
小新同学^O^1 天前
简单学习 --> Spring事务
数据库·学习·spring
前进的李工1 天前
MySQL慢查询日志优化实战
数据库·mysql·性能优化