我在PL / SQL中执行这些sqls。
原始的sql是:
select * from (
select RecID,TaskNum from umstat.tostatinfo
where RecID in (select recid from umstat.tostatinfo where StreetID = 101 and checkNum > 0)
order by recID desc
) where rownum >= 1 and rownum <= 50
RecID
是umstat.tostatinfo的主键。这个sql将清空列TaskNum
并给出以下结果:
奇怪的是,如果我删除第四行(order by recID desc
)或删除where(where rownum >= 1 and rownum <= 50
)强加的最外层限制,那么列TaskNum
将会活跃起来:
为了使用order by
和rownum
提供的功能,我将原始sql简化为更简洁的一个:
select * from (
select RecID,TaskNum from umstat.tostatinfo
where StreetID = 101 and checkNum > 0
order by recID desc
) where rownum >= 1 and rownum <= 50
这个sql的结果看起来很正常:
更多测试:
将子查询替换为普通ID (447914,447912,447905)
:
select * from (
select RecID,TaskNum from umstat.tostatinfo
where RecID in (447914,447912,447905)
order by recID desc
) where rownum >= 1 and rownum <= 50
结果是:
在子查询中将recid
更改为TaskNum
:
select * from (
select RecID,TaskNum from umstat.tostatinfo
where TaskNum in (select TaskNum from umstat.tostatinfo where StreetID = 101 and checkNum > 0)
order by recID desc
) where rownum >= 1 and rownum <= 50
结果是:
我想知道是什么让所有这些都发生在地下,感谢你的时间。