平均查询 ORA-00936 错误
Posted
技术标签:
【中文标题】平均查询 ORA-00936 错误【英文标题】:average query ORA-00936 error 【发布时间】:2018-07-10 14:32:35 【问题描述】: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
特定船舶的平均重量,同时列出特定船舶的货物,无法识别错误
【问题讨论】:
AS AVERAGE
之前的额外逗号。应该是 ) AS AVERAGE
而不是 ), AS AVERAGE
。在SELECT
和AVG
之间还有一个额外的左括号
其中重量 = 650.... 这不意味着平均值为 650.... 那么您是否想要平均重量为 650 或更大?如果是这样,就需要一个有子句。
【参考方案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
。
【讨论】:
【参考方案2】:你似乎想要:
SELECT consignmentNo, VoyageNo, Weight, avg.AVERAGE
FROM consignment CROSS JOIN
(SELECT AVG(WEIGHT) AS AVERAGE FROM consignment) avg
WHERE Weight = 650;
【讨论】:
【参考方案3】:您的查询中有一个额外的,
(在AS AVERAGE
之前),而您在Weight
之后缺少一个,
。 from
和 where
的顺序也不正确。试试这个:
SELECT consignmentNo, VoyageNo, Weight,
(SELECT (AVG(WEIGHT) FROM consignment) AS AVERAGE,
FROM consignment
WHERE Weight = 650;
【讨论】:
这也不是有效的语法,在哪里和从不正确的顺序。以上是关于平均查询 ORA-00936 错误的主要内容,如果未能解决你的问题,请参考以下文章