ORA-00979: 不是 GROUP BY 表达式
为什么这可行,
SELECT DISTINCT FIRSTNAME, LASTNAME
FROM books, CUSTOMERS, orders, orderitems
WHERE STATE IN('FL ', 'GA')
GROUP BY orders.order#, firstname, lastname
HAVING SUM(retail*quantity) > 80
但当 firstname, lastname
从 group by
中删除时却不起作用?
ORA-00979: 不是 GROUP BY 表达式
Why does this work
SELECT DISTINCT FIRSTNAME, LASTNAME
FROM books, CUSTOMERS, orders, orderitems
WHERE STATE IN('FL ', 'GA')
GROUP BY orders.order#, firstname, lastname
HAVING SUM(retail*quantity) > 80
but when firstname, lastname
is removed from group by
it doesn't?
ORA-00979: not a GROUP BY expression
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如我可以猜测的,
首先执行 GROUP BY 操作,然后执行 DISTINCT。在 GROUP BY 子句中,您必须指示所有非聚合。例如,您不得执行以下操作:
您应该这样做:
As I can guess
First of all GROUP BY operation is performed and then DISTINCT. In GROUP BY clause you must indicate all non-aggregates . For example you are not permitted to do the following:
You should do it by this way:
在这种情况下,如果从
group by
中删除firstname、lastname
,您会收到该错误,因为您正在SELECT
列不在GROUP BY
表达式中,或者不是聚合/函数的一部分(即 MIN、MAX、AVG 等)。您还可以消除
DISTINCT
。In that case where
firstname, lastname
are removed from thegroup by
, you get that error because you'reSELECT
ing a column(s) that aren't in theGROUP BY
expression, or aren't part of an aggregation/function (i.e. MIN, MAX, AVG, and others).You could also eliminate the
DISTINCT
as well.