SQL/oracle应用--查询最大版本值语句
直接上代码:
说明:表是以'CAK_APPID'和'CAK_VERSION '为复合主键。查一条语句进行的。
图示:
[img]http://dl2.iteye.com/upload/attachment/0096/8818/46e20a95-bfbf-38f7-a7c3-52f32eb84c8f.jpg[/img]
直接上代码:
//(1)
select t.* from tableA t where not exists(select 1 from tableA where CAK_APPID=t.CAK_APPID and CAK_APPID ='test1' and CAK_VERSION>t.CAK_VERSION)
//(2)
select * from tableA where CAK_VERSION = (select max(CAK_VERSION) from tableA where CAK_APPID = 'test1' )
//(3)用时最短
select * from (select t.* from tableA t where t.cak_appid = 'test1' order by CAK_VERSION desc) where rownum=1
说明:表是以'CAK_APPID'和'CAK_VERSION '为复合主键。查一条语句进行的。
图示:
[img]http://dl2.iteye.com/upload/attachment/0096/8818/46e20a95-bfbf-38f7-a7c3-52f32eb84c8f.jpg[/img]

本文介绍了三种查询数据库中最大版本值的方法,包括使用NOT EXISTS、子查询及ROWNUM限制等技巧,适用于复合主键场景。
1685

被折叠的 条评论
为什么被折叠?



