我试图解决这个问题https://www.hackerrank.com/challenges/placements/problem 以下代码跳转出错
CREATE VIEW T AS (
SELECT STUDENTS.ID ,STUDENTS.NAME,PACKAGES.SALARY,FRIENDS.FRIEND_ID
FROM STUDENTS JOIN FRIENDS ON STUDENTS.ID=FRIENDS.ID
JOIN PACKAGES ON STUDENTS.ID=PACKAGES.ID
);
CREATE VIEW T2 AS (
SELECT T.NAME
FROM T JOIN PACKAGES ON T.FRIEND_ID=PACKAGES.ID
WHERE T.SALARY<PACKAGES.SALARY
ORDER BY PACKAGES.SALARY;
);
SELECT *
FROM T2;
但是这个
CREATE VIEW T AS (
SELECT STUDENTS.ID ,STUDENTS.NAME,PACKAGES.SALARY,FRIENDS.FRIEND_ID
FROM STUDENTS JOIN FRIENDS ON STUDENTS.ID=FRIENDS.ID
JOIN PACKAGES ON STUDENTS.ID=PACKAGES.ID
);
SELECT T.NAME
FROM T JOIN PACKAGES ON T.FRIEND_ID=PACKAGES.ID
WHERE T.SALARY<PACKAGES.SALARY
ORDER BY PACKAGES.SALARY;
作品。为什么?这是因为我创建了多个视图还是其他原因?
1条答案
按热度按时间ocebsuys1#
试着去掉括号:
您会注意到,我引入了表别名,因此查询更易于编写和读取。
括号不是
CREATE VIEW
语法,因此查询被解释为子查询。我想这就打乱了对ORDER BY
.