3

我习惯于在 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
4

1 回答 1

2

可以使用列名、列别名或列位置在 ORDER BY 和 GROUP BY 子句中引用为输出选择的列。列位置是整数,以 1 开头

来自:http ://dev.mysql.com/doc/refman/5.0/en/select.html

除非您在该表中只有 1 列,否则它应该可以正常运行。但是,我的建议是引用您要尝试的任何内容的列名(或别名)GROUP BY

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

编辑2:好的,我看到你已经更新了你的问题。为什么不代替ORDER BY 2, you ORDER BY grantmakerName(如果那是您要订购的列?)

于 2012-11-26T07:49:51.827 回答