php - 解释这个 Zend_Select and Convert to SQL Query?

标签 php mysql zend-framework zend-db

$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/

相关文章:

mysql - 将表的外键与该表的最大主键连接

php - 如何在 Zend2 中为集合呈现自定义模板

php - Zend_Http_Client 不存储 cookie

php - mySQL 到 PHP 动态表

javascript - 从函数返回两个变量

PHP session 不会过期。曾经

PHP 和 mod_dbd

mysql - 如何编写查询或过程

javascript - 选择 html 更改其他 从 onchange 函数中选择 html

mysql - Zend_Date 本地化日期