简体   繁体   中英

Solely COUNT(*) from Zend_DB Select Statement (Subquery)

I'm trying to wrap a count(*) query around an existing Zend_Db select statement, but all I was able to get is:

SELECT `t`.*, COUNT(*) AS `TotalRecords` FROM (SELECT ....) AS `t`

However I like to get rid of the t.* as I only need the count(*).

This is my code so far:

$db = Zend_Registry::get('db');
$select = $dbmodel->getSomething(); //zend select object
$outterSelect = new Zend_Db_Select($db);
$outterSelect->from($select)->columns(array('TotalRecords' => new Zend_Db_Expr('COUNT(*)')));
echo $outterSelect->__toString();

Any help is appreciated!

您可以简单地写:

$outterSelect->from($select, 'COUNT(*) as TotalRecords');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM