寻找最大部分
Finding Maximum Part
我有 tables with columns in the parentheses 就像这样:
Employee (Empno, Empname, City)
Project (Pno, Pname)
Part (Partno, Partname, Color)
Use (Pno, Partno)
Works (Empno, Pno)
我使用的是 ORACLE 11g 快捷版
我的查询:
SELECT *
FROM (SELECT p.Pname AS Project_name
FROM (SELECT COUNT(Color) AS colorPart, U.Pno, P.Color
FROM Part P
JOIN Use u
ON u.Partno = p.Partno
and p.Color = 'Red'
GROUP BY Color, Pno
ORDER BY colorPart DESC)
WHERE rownum = 1) AS Final
JOIN Project p
ON Final.Pno = p.Pno;
这里出现错误:ORA-00933: SQL 命令未正确结束
您可以将当前查询重写为
SELECT p.Pname AS Project_name
FROM (SELECT Pno
FROM (SELECT Pno, COUNT(Color) AS ColorPart
FROM Part P
JOIN Use u
ON u.Partno = p.Partno
AND p.Color = 'Red'
GROUP BY Color, Pno
ORDER BY ColorPart DESC)
WHERE rownum = 1) Final
JOIN Project p
ON Final.Pno = p.Pno
哪里
别名 Final
之前的 AS
应该被删除,因为别名是
与其他一些 DBMS 不同,Oracle DB 中不允许使用子查询
p.Pname
应该在最外层的查询中
我有 tables with columns in the parentheses 就像这样:
Employee (Empno, Empname, City)
Project (Pno, Pname)
Part (Partno, Partname, Color)
Use (Pno, Partno)
Works (Empno, Pno)
我使用的是 ORACLE 11g 快捷版
我的查询:
SELECT *
FROM (SELECT p.Pname AS Project_name
FROM (SELECT COUNT(Color) AS colorPart, U.Pno, P.Color
FROM Part P
JOIN Use u
ON u.Partno = p.Partno
and p.Color = 'Red'
GROUP BY Color, Pno
ORDER BY colorPart DESC)
WHERE rownum = 1) AS Final
JOIN Project p
ON Final.Pno = p.Pno;
这里出现错误:ORA-00933: SQL 命令未正确结束
您可以将当前查询重写为
SELECT p.Pname AS Project_name
FROM (SELECT Pno
FROM (SELECT Pno, COUNT(Color) AS ColorPart
FROM Part P
JOIN Use u
ON u.Partno = p.Partno
AND p.Color = 'Red'
GROUP BY Color, Pno
ORDER BY ColorPart DESC)
WHERE rownum = 1) Final
JOIN Project p
ON Final.Pno = p.Pno
哪里
-
别名
AS
应该被删除,因为别名是 与其他一些 DBMS 不同,Oracle DB 中不允许使用子查询
p.Pname
应该在最外层的查询中
Final
之前的