gpt4 book ai didi

MySQL 错误 1064 (v 5.0.96) GROUP BY 子句

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

我习惯于在 Oracle 数据库上运行,所以我不太确定如何解决这个问题。我已将查询的一个简单示例缩小为以下内容:

 SELECT 0 as gm_rowID, 
'-ALL Grantmakers-' as grantmakerName
FROM dual
GROUP BY 2

phpMyAdmin 运行 SQL 时出现以下错误:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY 2 LIMIT 0, 30' at line 1

Oracle 可以很好地运行此查询。 MySQL 可以在没有 GROUP BY 子句的情况下运行查询。有什么想法吗?

--这是整个查询:

SELECT 
p.grantmaker_rowid as gm_rowID,
gm.grantmaker_companyName as grantmakerName
FROM grantmaker_info gm, proposal_submission p
WHERE 0=0
AND p.grantmaker_rowid = gm.grantmaker_rowid
UNION
SELECT
0 as gm_rowID,
'-ALL Grantmakers-' as grantmakerName
FROM dual
ORDER BY 2
GROUP BY 2
LIMIT 0 , 30

最佳答案

Columns selected for output can be referred to in ORDER BY and GROUP BY clauses using column names, column aliases, or column positions. Column positions are integers and begin with 1

发件人:http://dev.mysql.com/doc/refman/5.0/en/select.html

除非该表中只有 1 列,否则它应该可以正常运行。然而,我的建议是引用您尝试GROUP BY 的列名称(或别名)。

编辑:我唯一的其他建议是包括该表的 SHOW CREATE TABLE 输出。

edit2:好的,我看到您已经更新了您的问题。为什么不使用ORDER BY 2,而是ORDER BY grantmakerName(如果这是您要排序的列?)

关于MySQL 错误 1064 (v 5.0.96) GROUP BY 子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13560620/

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