首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >zend findManyToManyRowset子选组依据

zend findManyToManyRowset子选组依据
EN

Stack Overflow用户
提问于 2012-03-19 21:49:38
回答 1查看 345关注 0票数 1

我需要为交叉表查找具有order by和group by选择的findManyToManyRowset。

用于交叉点子选择的SQL如下所示:

代码语言:javascript
复制
$order = "select *
from intersection
order by someCol desc";

$group = "select order.*
from ($order) as order
group by order.otherCol";

结果子选择字符串为$group。

findManyToManyRowset的第五个参数$select应该是Zend_Db_Table_Select,但我被困在这里了,因为我不能用Zend_Db_Table_Select做真正的子选择,也不能用findManyToManyRowset(..)有字符串

代码语言:javascript
复制
if ($select === null) {
    $select = $matchTable->select();
} else {
    $select->setTable($matchTable);
}

    $select->from(array('i' => $interName), array(), $interSchema)
           ->joinInner(array('m' `enter code here`=> $matchName), $joinCond, Zend_Db_Select::SQL_WILDCARD, $matchSchema)
           ->setIntegrityCheck(false);

他们破坏了我在$select ($group)中所做的一切

EN

Stack Overflow用户

发布于 2012-03-20 15:46:22

问题解决了。

我更改SQL字符串this way

代码语言:javascript
复制
select
*
from someTable st1
where groupCol =
    (
    select
        max(st2.groupCol)
    from someTable st2
    where
        st1.firstId=st2.firstId
        and st1.secondId=st2.secondId
        ....
        and etc
    )
--and groupResult=1;

因此,在不使用order by和不使用join的情况下,我得到了相同的结果。

Zend code:

代码语言:javascript
复制
    $matchTable,$intersectionTable - should be instance of Zend_Db_Table_Abstract with correct reference map

        $max = $intersectionTable->select()
                ->from(array('mx' => 'intersectionTableName'), new Zend_Db_Expr("max(mx.groupCol)"))
                ->where('i.firstId = mx.firstId')
                ->where('i.secondId = mx.secondId')
                ...
                -> etc ;


        $select = $matchTable->select()
//                  ->where('i.groupResult = ?', true) optional, in case we would like to filter result rowset by grouped value
                    ->where('i.groupCol = ?', $max);



        $result = $row->findManyToManyRowset($matchTable, $intersectionTable, null, null, $select);
票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9771409

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档