我有一个查询如下:
select status, count(id) as units from myTable group by status
我的显示器上有一个Zend_Db_Table对象,用于正在使用的表,我正在尝试下面提到的片段来创建上面的查询:
$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');
试试这个。
$select = new Zend_Db_Select;
$select->from(
# table
array(
't' => 'myTable'
),
# columns
array(
'status' => 'DISTINCT(STATUS)',
'units' => 'COUNT(id)',
));
->group('status');
问题是,如果->from(
子句
Zend_Db_Select
将自动将table.*
添加到查询中