以下plsql语句如何改为取最新一条数据
原语句:select(selectt1.mcfromtable1t1wheret1.key=t.keyandt1.rownum=1)fromtablet如上,只能取随机一...
原语句:select (select t1.mc
from table1 t1
where t1.key = t.key
and t1.rownum = 1)
from table t
如上,只能取随机一条数据,并不能取最新一条
若改为
select (select mc
from (select t1.key,
t1.mc,
t1.shijian,
row_number() over(partition by t1.key order by t1.shijian desc) rn
from table1 t1)
where key = t.key
and rn = 1)
from table t
这个倒是可以,可惜table1表数据过大,非常影响速度。
所以,请教下各位高手,有什么方法能实现需求吗? 展开
from table1 t1
where t1.key = t.key
and t1.rownum = 1)
from table t
如上,只能取随机一条数据,并不能取最新一条
若改为
select (select mc
from (select t1.key,
t1.mc,
t1.shijian,
row_number() over(partition by t1.key order by t1.shijian desc) rn
from table1 t1)
where key = t.key
and rn = 1)
from table t
这个倒是可以,可惜table1表数据过大,非常影响速度。
所以,请教下各位高手,有什么方法能实现需求吗? 展开
1个回答
展开全部
select mc
from (select t1.key, t1.mc, t1.shijian
from table1 t1
order by t1.shijian desc
)
where rownum = 1
from (select t1.key, t1.mc, t1.shijian
from table1 t1
order by t1.shijian desc
)
where rownum = 1
更多追问追答
追问
select (select mc
from (select t1.mc
from table1 t1
where t1.key = t.key
order by t1.shijian desc)
where rownum = 1)
from table t
这样?
追答
select mc
from (select t1.key, t1.mc, t1.shijian
from table1 t1
order by t1.shijian desc
)
where rownum = 1 就是这样啊,有什么问题吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |