如何在不使用 WITH 块的情况下过滤 oracle 中只有 rank=1 的记录
How to filter records having only rank=1 in oracle without using WITH block
创建了一个示例 table 并尝试过滤排名为 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;
您需要从查询中删除 as
关键字。别名 table,AS
是不允许的。 AS
可以指定为列指定别名。
删除 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 中的 运行 示例。
创建了一个示例 table 并尝试过滤排名为 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;
您需要从查询中删除 as
关键字。别名 table,AS
是不允许的。 AS
可以指定为列指定别名。
删除 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 中的 运行 示例。