gpt4 book ai didi

mysql - ORA-00979 : not a GROUP BY expression for Oracle but not valid for MySQL in context of clause difference

转载 作者:可可西里 更新时间:2023-11-01 07:22:08 25 4
gpt4 key购买 nike

我已经在 Oracle 中运行了这个查询

select studentid, attndmark
from attendance_master m,
attendance_detail d
where m.attnid = d.attendid
group by studentid

得到错误:

ORA-00979: not a GROUP BY expression

错误很好,我知道 select 子句中列列表的问题。但类似的查询在 MySQL 中有效。

SELECT aff.akey, username
FROM `affiliates` aff,
affstats ast
WHERE aff.akey = ast.akey
group by aff.akey

我需要一个可以在 RDBMS Oracle/Mysql 和 MSSQL 上运行的查询技巧。

有什么诀窍?

最佳答案

MySQL 是错误的,因为它不符合 SQL 标准(在这种情况下甚至不符合常识)。它允许 SELECT 中的列不是聚合函数的参数并且不在 GROUP BY 中。文档明确指出这些值来自“不确定”行。

顺便说一下,您应该学习正确的显式 JOIN 语法。查询可以写成:

SELECT aff.akey, MAX(username)
FROM affiliates aff JOIN
affstats ast
ON aff.akey=ast.akey
GROUP BY aff.akey;

这将适用于两个数据库。

关于mysql - ORA-00979 : not a GROUP BY expression for Oracle but not valid for MySQL in context of clause difference,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34158434/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com