1

创建了一个示例表并尝试过滤排名为 1 的记录,但失败了

错误

ORA-00933:SQL 命令未正确结束 00933. 00000 - “SQL 命令未正确结束” *原因:
*操作:行错误:30 列:3

CREATE TABLE exam_result (
points int,
last_name varchar(255),
first_name varchar(255) );

INSERT INTO exam_result VALUES (70, 'Emyr', 'Downes');
INSERT INTO exam_result VALUES (70, 'Dina', 'Morin');
INSERT INTO exam_result VALUES (80, 'Evie-May', 'Boyer');
INSERT INTO exam_result VALUES (60, 'Nora', 'Parkinson');
INSERT INTO exam_result VALUES (40, 'Trystan', 'Oconnor');
INSERT INTO exam_result VALUES (90, 'Eryk', 'Myers');

SELECT * FROM
(
  SELECT
  RANK() OVER(ORDER BY points DESC) AS ranking,
  first_name,
  last_name,
  points
  FROM exam_result
) AS a
WHERE ranking <= 1;
4

2 回答 2

2

您需要as从查询中删除关键字。AS不允许给表起别名。AS可以指定为列提供别名。

于 2021-02-17T15:03:23.603 回答
0

删除AS关键字。例如:

SELECT * FROM
(
  SELECT
  RANK() OVER(ORDER BY points DESC) AS ranking,
  first_name,
  last_name,
  points
  FROM exam_result
) a
WHERE ranking <= 1;

请参阅db<>fiddle的运行示例。

于 2021-02-17T15:05:39.573 回答