我只想获得此查询的第一个结果,但每当我写下LIMIT时。 Oracle SQL Developer抛出了这个错误
* ORA-00933:SQL命令未正确结束
00933. 00000 - “SQL命令未正确结束”
*原因:
动作:
行错误:6列:7
以下是代码:
SELECT IDBAR FROM ( SELECT PARRANDEROS.FRECUENTAN.ID_BAR as IDBAR,
COUNT(PARRANDEROS.FRECUENTAN.ID_BAR) c
FROM PARRANDEROS.FRECUENTAN
GROUP BY PARRANDEROS.FRECUENTAN.ID_BAR
ORDER BY c DESC
)
LIMIT 1;
我也尝试过这种方法:
SELECT IDBAR FROM ( SELECT PARRANDEROS.FRECUENTAN.ID_BAR as IDBAR,
COUNT(PARRANDEROS.FRECUENTAN.ID_BAR) c
FROM PARRANDEROS.FRECUENTAN
GROUP BY PARRANDEROS.FRECUENTAN.ID_BAR
ORDER BY c DESC
LIMIT 1
);
非常感谢。
答案 0 :(得分:1)
感谢@Jim Garrison。解决方案是使用ROWNUM属性:
SELECT IDBAR FROM ( SELECT PARRANDEROS.FRECUENTAN.ID_BAR as IDBAR,
COUNT(PARRANDEROS.FRECUENTAN.ID_BAR) c
FROM PARRANDEROS.FRECUENTAN
GROUP BY PARRANDEROS.FRECUENTAN.ID_BAR
ORDER BY c DESC
)
WHERE ROWNUM <= 1;