select 单号,max( 流水)流水 from tb group by 单号+++++++++1
不好意思 可能我没说清楚,其实后面还有好多列的 单号 流水 操作人 A 1 TONY A 2 JIMMY A 3 JIMMYB 1 JIMMY B 2 JIMMY C 1 TONYD 1 JIMMY D 2 TONY现在想写个语句 只列出每个单号的流水最大的那条记录 如 A 3 JIMMY B 2 JIMMY C 1 TONY D 2 TONY 是整条记录显示
select * from tb a where exists (select 1 from (select 单号,max( 流水)流水 from tb group by 单号 ) b where a.单号=b.单号 and a.流水 =b.流水 )
select * from tb t where is not exists( select 1 from tb where 单号=t.单号 and 流水>t.流水 )
from tb
group by 单号
from tb
group by 单号+++++++++1
单号 流水 操作人
A 1 TONY
A 2 JIMMY
A 3 JIMMYB 1 JIMMY
B 2 JIMMY
C 1 TONYD 1 JIMMY
D 2 TONY现在想写个语句 只列出每个单号的流水最大的那条记录
如
A 3 JIMMY
B 2 JIMMY
C 1 TONY
D 2 TONY
是整条记录显示
from tb a
where exists (select 1 from (select 单号,max( 流水)流水
from tb
group by 单号 ) b where a.单号=b.单号 and a.流水
=b.流水
)
select * from tb t where is not exists(
select 1 from tb where 单号=t.单号 and 流水>t.流水
)