1 有2个表结构如下:
A表结构
Id value
1 10
2 20
3 30
4 30
5 30
6 20
7 40
B表结构
Id column
2 aaa
3 bbb
4 ccc
5 ddd
9 eee
A表和B表ID关联以后,取出A表value最大的所有记录
结果:
ID Value column
3 30 bbb
4 30 ccc
5 30 ddd
select * from A,B,
(select Max(value) as MaxValue from A where exists(select 1 from B where b.id=a.id))T
where A.Value=T.MaxValue and A.ID = B.id
2 以下表A结构
id Qty Num
2 34 55
2 45 77
2 20 66
4 67 33
4 55 44
取出不同ID里面Num最大的记录集
select distinct id,
First_value(Qty) OVER (PARTITION BY id order by num desc),
First_value(num) OVER (PARTITION BY id order by num desc)
from A
结果:
id Qty Num
2 45 77
4 55 44
Oracle分析函数——函数RANK,DENSE_RANK,FIRST,LAST…