这是SQL Server中的单个SQL语句
Integer.parseInt(String)
然后,我尝试将其应用于Oracle 11g(不支持前n个查询的Oracle 12c)
SELECT
a.EMPNUM,
(SELECT TOP 1 NAMEKO
FROM PA0001
WHERE COMPCD = a.COMPCD
AND EMPNUM = a.LASTUP
ORDER BY EDDATE DESC) AS LASTNM,
(SELECT TOP 1 NAMEKO
FROM PA0001
WHERE COMPCD = a.COMPCD
AND EMPNUM = a.FRSTUP
ORDER BY EDDATE DESC) AS FIRSNM
FROM PA0000 a
然后我收到了错误
ORA-00904:“A”。“FRSTUP”:标识符无效。
如何重写Oracle的查询?
答案 0 :(得分:1)
首先你需要添加别名" a"表PA0000
以避免错误ORA-00904: "A"."FRSTUP": invalid identifier.
答案 1 :(得分:1)
使用rownum = 1将选择一个不依赖于order by子句的随机值(而不是块如何在磁盘上对齐)
12c具有此功能( FETCH FIRST {n} ROWS ONLY 子句)
在11.2及更低版本中,使用 row_number()是最方便的方法
选择在架构中创建的最新对象(单个)的示例:
select *
from (select user_objects.object_name,
user_objects.object_id,
user_objects.created,
row_number () over (order by user_objects.created desc) as rn
from user_objects) view_uo
where view_uo.rn = 1
查看最新的10个对象将是 rn< = 10
然后只需修改此选项即可包含您的选择。
答案 2 :(得分:0)
根据我对您问题的理解,您可以使用level, connect by prior
按如下方式获得结果:
SELECT EMPNO FROM EMP WHERE HIREDATE IN
(SELECT MAX(HIREDATE) FROM EMP WHERE LEVEL<=1 CONNECT BY PRIOR HIREDATE>HIREDATE GROUP BY LEVEL) ORDER BY HIREDATE DESC;
希望这能解决您的要求......