今天偶尔然发现分页的时候突然发现了这个 Partition By 函数, 当然这个与分页关系不是很大, 被不小心吃瓜捞了
这个分区函数partition by可以用在如下场景
查找与往来商户账目种的最后一笔结算
在没有用Partition By 函数, 类似如下查询 select * from table1 whre id in (select min(id) from table group by ss order by dt desc)
使用 Partition By 函数,
查找商户相同, 按日期倒序排序的第一条信息
select * from (select id, 商户, 金额, dtCreate, ROW_NUMBER() over(partition by 商户 order by dtCreate desc) as snid from 账单)
as t where t.snid = 1