加入时的子查询不正确 [英] Sub Query at join not coming in right way

查看:54
本文介绍了加入时的子查询不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我遇到了一个问题.我发现无法删除由 zend 在查询生成的子查询中生成的引号,该子查询放置在连接操作中.$selectInnerQuery 创建在连接操作中使用的子查询,称为内部答案表.这用于连接答案表.$select 用于最终查询.请帮我解决这个问题...

Hiii, Currently I am stuck with a problem. I am finding no way to remove quotes generated by the zend on query generation of a sub query which is placed in a join operation. The $selectInnerQuery creates the sub query which is used in the join operation this is called as inneranswer table. This is used to join with answer table. $select is used for the final query. Please help me on this...

$selectInnerQuery= $sql->select()->from(array('answer' => 'tblanswer'))->columns(array('aid'        =>  new Expression('answer.aid'),'count' => new Expression('count(answer.qid)')));


$innerstatement = $sql->getSqlStringForSqlObject($selectInnerQuery);

$select = $sql->select()->from(array('answer' => 'tblanswer'))->columns($fieldsToSelect);
$select->join(array('inneranswer' =>  $innerstatement), 'inneranswer.aid = answer.aid', array(),'inner');

我从 zend 得到的查询是

The query that I am getting from zend is

SELECT `answer`.* FROM `tblanswer` AS `answer` 
inner join `SELECT answer.aid AS ``aid``, count(answer.qid) AS ``count`` FROM ``tblanswer`` AS ``answer`` WHERE answer.qid !=0 GROUP BY answer.qid, answer.baid` AS `inneranswer` ON `inneranswer`.`aid` = `answer`.`aid` 

我尝试过新表达式,但它在连接操作中不起作用.

I have tried new Expression but it does not work in join operation.

推荐答案

今天遇到了同样的问题.联接表数组应包含 Select 对象而不是 select 查询.

Came across the same issue today. Join table array should contain Select object instead of select query.

$selectObj = $sql->select()->from(array('answer' => 'tblanswer'))->columns(array('aid'        =>  new Expression('answer.aid'),'count' => new Expression('count(answer.qid)')));
$select = $sql->select()->from(array('answer' => 'tblanswer'))->columns($fieldsToSelect);
$select->join(array('inneranswer' =>  $selectObj), 'inneranswer.aid = answer.aid', array(),'inner');

这篇关于加入时的子查询不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆