Zend_Db_Table_Select를 사용하여 SQL 쿼리에서 COUNT()를 가져 오는 데 문제가 있습니다. 생성해야하는 SQL이 실제로 작동하기 때문에 가능한 버그 일 수 있습니다. 여기 젠드 선택 쿼리 :이 오류 제공Zend_Db_Select - 조인과 카운트 - 가능한 젠드 버그?
$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);
($이 예에서 table1
로 이름을 바꾼 Zend_Db_Table입니다) ...
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]
...은 데이터베이스에 대해 실행할 때 오류없이 예상 된 결과를 반환합니다. 어떤 아이디어가 계속되고, 왜 오류가 발생하며 어떻게 해결할 수 있습니까?
SQL은 오류를 반환하는 엔터티이므로 생성 된 SQL 문이 작동한다고 가정하면 Zend_Db_Select가 범인이 될 수있는 방법을 이해하기 어렵습니다. 다른 쿼리가 실행되고 있습니까? 이 쿼리를 페이지 매김하고 있습니까? –