0

执行查询时收到以下错误消息

[2/2] DBALException: An exception occurred while executing 'SELECT DISTINCT s0_.id AS id0, s0_. AS 1 FROM shop s0_ WHERE s0_.isLocked = ? ORDER BY s0_.owner_id DESC LIMIT 20 OFFSET 0' with params [0]:

SQLSTATE[42000]: Syntax error or access violation: 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 'AS 1 FROM shop s0_ WHERE s0_.isLocked = 0 ORDER BY s0_.owner_' at line 1   +

[1/2] PDOException: SQLSTATE[42000]: Syntax error or access violation: 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 'AS 1 FROM shop s0_ WHERE s0_.isLocked = 0 ORDER BY s0_.owner_' at line 1  

这应该是查询错误还是其他原因?因为看来我的查询是合法的。

4

2 回答 2

1
SELECT DISTINCT s0_.id AS id0, s0_. AS 1

应该是查询错误。您正在从表 s0_ 和一个没有同一个表名称的字段中选择唯一 ID,但一个字段不能没有名称。

您应该添加一个字段名,如下所示:

SELECT DISTINCT s0_.id AS id0, s0_.FIELDNAME AS `1`
于 2013-10-21T11:58:00.810 回答
0
SELECT DISTINCT s0_.id AS id0, s0_. AS `1`

将 1 包裹在 ``

以及上面评论中缺少的字段名称......

于 2013-10-21T11:42:40.750 回答