gpt4 book ai didi

php - Zend 按字段选择分组

转载 作者:行者123 更新时间:2023-11-29 00:41:17 24 4
gpt4 key购买 nike

我有一个查询如下:

select status, count(id) as units from myTable group by status

我有一个 Zend_Db_Table 对象在我的 displosal 中用于正在使用的表,我正在尝试下面提到的代码片段来创建上面的查询:

$objTable= new Application_Model_DbTable_MyTable();
$select = $objTable -> select(Zend_Db_Table::SELECT_WITH_FROM_PART)
-> setIntegrityCheck(false); // i am also using joins to create the query, but this is not of concern
$select -> columns(array(
'status' => new Zend_Db_Expr('DISTINCT(STATUS)'),
'units' => new Zend_Db_Expr('COUNT(id)')
));
$select -> group('status');

从上面的片段创建的查询如下:

select myTable.*, DISTINCT(STATUS) as status, COUNT(id) as units from myTable group by status

我想从生成的查询中删除 myTable.*

最佳答案

$select = $db ->select()
->distinct()
->from('myTable',array('status', 'COUNT(id) as units'))
->group('status');

关于php - Zend 按字段选择分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12156057/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com