SQL/oracle应用--查询最大版本值语句

SQL/oracle应用--查询最大版本值语句

直接上代码:

//(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 '为复合主键。查一条语句进行的。

图示:


猜你喜欢

转载自caraly.iteye.com/blog/2063606
今日推荐