平均查询ORA-00936错误

时间:2018-07-10 14:32:36

标签: sql oracle average sqlplus

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

特定船舶的平均重量,也列出了该船舶的货物,也无法识别错误

3 个答案:

答案 0 :(得分:1)

您只是在寻找group by吗?

SELECT VoyageNo, AVG(Weight)
FROM consignment
GROUP BY VoyageNo;

如果您想要平均以及详细信息,则需要一个窗口函数:

SELECT c.*, AVG(Weight) OVER (PARTITION BY VoyageNo)
FROM consignment c;

这里假设VoyageNoship的意思。

答案 1 :(得分:0)

您的查询中有一个额外的,(在AS AVERAGE之前),并且在,之后缺少了Weightfromwhere的顺序也不正确。试试这个:

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;