$select->from(array('u'=>'user'),array('count'=>'distinct count(*)'))
->joinLeft(
array('d' => 'details'),
'u.detailsid = d.detailsid',
array());
我有:
SELECT * FROM user
LEFT JOIN details ON
details.detailsid = user.detailsid;
但是 count
适合哪里呢?
最佳答案
这是列。
SELECT DISTINCT count(*) AS count FROM user AS u
LEFT JOIN details AS d ON
d.detailsid = u.detailsid;
参见 http://framework.zend.com/manual/1.12/en/zend.db.select.html
In the second argument of the from() method, you can specify the columns to select from the respective table. If you specify no columns, the default is "*", the SQL wildcard for "all columns" […] You can list the columns in a simple array of strings, or as an associative mapping of column alias to column name. If you only have one column to query, and you don't need to specify a column alias, you can list it as a plain string instead of an array.
附带说明,您可以简单地回显查询以查看它会产生什么(与上面相同的页面):
Converting a Select Object to a SQL String - If you need access to a string representation of the SQL query corresponding to the
Zend_Db_Select
object, use the__toString()
method.
关于php - 解释这个 Zend_Select and Convert to SQL Query?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17060737/