select * from (
select *
from PAYHLST
where pay_no='200902270001'
order by hire_bgn_tm desc
) as v
fetch first 1 rows only
这个写法为什么不能得到 hire_bgn_tm 最大的那条记录呀?
实际得到的结果和
select * from (
select *
from PAYHLST
where pay_no='200902270001'
) as v
fetch first 1 rows only
得到的一致,不知道为什么,是不是db2不支持?
环境是ibm as400的服务器。谢谢!!
------解决方案--------------------------------------------------------
try:
select * from (
select *
from PAYHLST
where pay_no='200902270001'
) as v
order by hire_bgn_tm desc
fetch first 1 rows only
------解决方案--------------------------------------------------------
子查询排了序,外层查询没排序,结果就和没排序一样。
只用原SQL中的子查询就可以了:
select *
from PAYHLST
where pay_no='200902270001'
order by hire_bgn_tm desc
fetch first 1 row only