SQL> SELECT consignmentNo, VoyageNo, Weight
2 (SELECT (AVG(WEIGHT) FROM consignment), AS AVERAGE,
3 WHERE Weight = 650,
4 FROM consignment;
(SELECT (AVG(WEIGHT) FROM consignment), AS AVERAGE,
*
ERROR at line 2:
ORA-00936: missing expression
特定船舶的平均重量,也列出了该船舶的货物,也无法识别错误
答案 0 :(得分:1)
您只是在寻找group by
吗?
SELECT VoyageNo, AVG(Weight)
FROM consignment
GROUP BY VoyageNo;
如果您想要平均以及详细信息,则需要一个窗口函数:
SELECT c.*, AVG(Weight) OVER (PARTITION BY VoyageNo)
FROM consignment c;
这里假设VoyageNo
是ship
的意思。
答案 1 :(得分:0)
您的查询中有一个额外的,
(在AS AVERAGE
之前),并且在,
之后缺少了Weight
。 from
和where
的顺序也不正确。试试这个:
SELECT consignmentNo, VoyageNo, Weight,
(SELECT (AVG(WEIGHT) FROM consignment) AS AVERAGE,
FROM consignment
WHERE Weight = 650;
答案 2 :(得分:0)
您似乎想要:
SELECT consignmentNo, VoyageNo, Weight, avg.AVERAGE
FROM consignment CROSS JOIN
(SELECT AVG(WEIGHT) AS AVERAGE FROM consignment) avg
WHERE Weight = 650;