ORA-00979: 不是 GROUP BY 表达式

发布于 2024-10-31 05:39:30 字数 371 浏览 1 评论 0原文

为什么这可行,

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, lastnamegroup 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

执笔绘流年 2024-11-07 05:39:30

正如我可以猜测的,

首先执行 GROUP BY 操作,然后执行 DISTINCT。在 GROUP BY 子句中,您必须指示所有非聚合。例如,您不得执行以下操作:

SELECT FIRST_NAME, LAST_NAME
FROM EMPLOYEES
GROUP BY HIRE_DATE

您应该这样做:

SELECT FIRST_NAME, LAST_NAME
FROM EMPLOYEES
GROUP BY HIRE_DATE,FIRST_NAME, LAST_NAME

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:

SELECT FIRST_NAME, LAST_NAME
FROM EMPLOYEES
GROUP BY HIRE_DATE

You should do it by this way:

SELECT FIRST_NAME, LAST_NAME
FROM EMPLOYEES
GROUP BY HIRE_DATE,FIRST_NAME, LAST_NAME
梦纸 2024-11-07 05:39:30

在这种情况下,如果从 group by 中删除 firstname、lastname,您会收到该错误,因为您正在 SELECT 列不在 GROUP BY 表达式中,或者不是聚合/函数的一部分(即 MIN、MAX、AVG 等)。

您还可以消除 DISTINCT

In that case where firstname, lastname are removed from the group by, you get that error because you're SELECTing a column(s) that aren't in the GROUP 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文