简体   繁体   English

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

[英]Zend_Db_Select - Joins and Count - Possible Zend Bug?

I'm having an issue getting a COUNT() from a SQL query using Zend_Db_Table_Select, and I think it may be a possible bug because the SQL it should be generating actually works. 我在使用Zend_Db_Table_Select从SQL查询中获取COUNT()时遇到问题,我认为这可能是一个错误,因为它应该生成的SQL实际上可以工作。 Here's the Zend Select Query: ($this is a Zend_Db_Table, renamed to table1 in this example) 这是Zend Select查询:($这是一个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);

This gives the error: 这给出了错误:

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`

However, this query... 但是,此查询...

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]

...returns the expected results with no errors when run against the database. ...对数据库运行时返回预期结果,没有错误。 Any ideas whats going on, why the error, and how to get around it? 任何想法怎么回事,为什么会出现错误,以及如何解决呢?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM