Zend - SELECT语句“AS”

时间:2014-10-15 04:14:32

标签: php mysql zend-framework

我有以下查询

(select informed from evaluations where releases_id="1234") AS INFO

ZEND frameword query:

$get_details = $db->select()
                ->from(array('INFO'=>'evaluations'), 'informed')
                ->where('releases_id =?',"$row[id]");

以上给出了

SELECT `INFO`.`informed` FROM `evaluations` AS `INFO` WHERE (releases_id ='1214')

但我想得到

(select informed from evaluations where releases_id="1234") AS INFO

有人可以指导我构建正确的查询吗?

2 个答案:

答案 0 :(得分:1)

从您的请求开始:

$get_details = $db->select()
            ->from(array('INFO'=>'evaluations'), 'informed')
            ->where('releases_id =?',"$row[id]");

尝试重命名子查询,它应该可以工作:

$get_details = $db->select()->from(array('INFO' => $get_details))

答案 1 :(得分:0)

我不是Zend的专家,但你可以尝试一下

$subquery = $this->select()
    ->from('evaluations'), array('informed')) 
    ->where('releases_id = ?', $row[id]);

$main = $this->select()
    ->from('info' => new Zend_Db_Expr('(' . $subquery . ')'));

$result = $this->fetchAll($main);