mysql - Zend_Db_Select - 连接和计数 - 可能的 Zend Bug?

标签 mysql sql zend-framework mysql-error-1140

我在使用 Zend_Db_Table_Select 从 SQL 查询获取 COUNT() 时遇到问题,我认为这可能是一个错误,因为它应该生成的 SQL 实际上有效。这是 Zend Select Query:($这是一个 Zend_Db_Table,在本例中重命名为 table1)

    $select = $this->select();
    $select->setIntegrityCheck(false);

    // Select Count
    $select->from($this, array("COUNT(*) as 'COUNT'"))
           ->joinLeft('users', 'table1.userID = users.userID')
           ->joinLeft('table2', 'users.anotherKey = table2.anotherKey');

    // Add Where clause after join
    $select->where('users.anotherKey = ?', $anotherKeyValue);

这给出了错误:

SQLSTATE[42000]: Syntax error or access violation: 1140 
Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is 
illegal if there is no GROUP BY clause`

但是,这个查询...

SELECT COUNT(*) AS 'count' FROM table1
    LEFT JOIN users ON table1.userID = users.userID
    LEFT JOIN table2 ON users.anotherKey = table2.anotherKey
    WHERE users.anotherKey = [anotherKeyValue]

...在对数据库运行时返回预期结果且没有错误。任何想法发生了什么,为什么会出错,以及如何解决它?

最佳答案

您是否尝试查看 zend_db 生成的实际查询?

关于mysql - Zend_Db_Select - 连接和计数 - 可能的 Zend Bug?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2212215/

相关文章:

zend-framework - 在分页器部分访问请求参数

php - 对于高度变化的网站,memcache 或 memcached 有什么好处?

mysql - 如何使用 LIKE 或 REGEXP 对多个短语进行子查询?

php - 如何将 mysql 数据提取到带有垂直标题的 html 表中?

php - Doctrine 2.2/Symfony 2.2 : Persisting an entity with a composite foreign key

php - 需要有编辑按钮,将字段更改为可编辑;在提交时改变数据库

php - 插入大量日期

sql - 在 SELECT INTO 语句中添加额外的列

php - 获取 zf2 中的所有模块名称

使用 GET 在 mySql 查询上使用 PHP Zend_Paginator