• <tfoot id='gn9B4'></tfoot>

      1. <small id='gn9B4'></small><noframes id='gn9B4'>

        <legend id='gn9B4'><style id='gn9B4'><dir id='gn9B4'><q id='gn9B4'></q></dir></style></legend>

        <i id='gn9B4'><tr id='gn9B4'><dt id='gn9B4'><q id='gn9B4'><span id='gn9B4'><b id='gn9B4'><form id='gn9B4'><ins id='gn9B4'></ins><ul id='gn9B4'></ul><sub id='gn9B4'></sub></form><legend id='gn9B4'></legend><bdo id='gn9B4'><pre id='gn9B4'><center id='gn9B4'></center></pre></bdo></b><th id='gn9B4'></th></span></q></dt></tr></i><div id='gn9B4'><tfoot id='gn9B4'></tfoot><dl id='gn9B4'><fieldset id='gn9B4'></fieldset></dl></div>

          <bdo id='gn9B4'></bdo><ul id='gn9B4'></ul>

        子查询 ActiveRecord Yii

        Sub-queries ActiveRecord Yii(子查询 ActiveRecord Yii)

          <small id='Pw1wq'></small><noframes id='Pw1wq'>

            • <bdo id='Pw1wq'></bdo><ul id='Pw1wq'></ul>
            • <tfoot id='Pw1wq'></tfoot>
              <i id='Pw1wq'><tr id='Pw1wq'><dt id='Pw1wq'><q id='Pw1wq'><span id='Pw1wq'><b id='Pw1wq'><form id='Pw1wq'><ins id='Pw1wq'></ins><ul id='Pw1wq'></ul><sub id='Pw1wq'></sub></form><legend id='Pw1wq'></legend><bdo id='Pw1wq'><pre id='Pw1wq'><center id='Pw1wq'></center></pre></bdo></b><th id='Pw1wq'></th></span></q></dt></tr></i><div id='Pw1wq'><tfoot id='Pw1wq'></tfoot><dl id='Pw1wq'><fieldset id='Pw1wq'></fieldset></dl></div>
              <legend id='Pw1wq'><style id='Pw1wq'><dir id='Pw1wq'><q id='Pw1wq'></q></dir></style></legend>

                <tbody id='Pw1wq'></tbody>

                  本文介绍了子查询 ActiveRecord Yii的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  Yii 中的 ActiveRecord 是否可以进行子查询?

                  Is it possible to make sub-queries in ActiveRecord in Yii?

                  我有一个这样的查询:

                  select * from table1where table1.field1 in (select table2.field2 from table2)

                  我目前正在使用空闲代码:

                  i'm currently using the fallowing code:

                  object1::model()->findAll(array('condition'=>'t.field1 in (select table2.field2 from table2)'))


                  我想知道是否有一种方法可以在不使用 SQL 和不使用连接的情况下构造子查询.


                  i would like to know if there is a manner to construct the sub-query without using SQL, and without using joins.

                  有什么解决办法吗?

                  提前致谢.

                  推荐答案

                  首先通过 db 字段查找 doublets:

                  First find doublets by db fields:

                  $model=new MyModel('search');
                  $model->unsetAttributes();
                  
                  $criteria=new CDbCriteria();
                  $criteria->select='col1,col2,col3';
                  $criteria->group = 'col1,col2,col3';
                  $criteria->having = 'COUNT(col1) > 1 AND COUNT(col2) > 1 AND COUNT(col3) > 1';
                  

                  获取子查询:

                  $subQuery=$model->getCommandBuilder()->createFindCommand($model->getTableSchema(),$criteria)->getText();
                  

                  添加子查询条件:

                  $mainCriteria=new CDbCriteria();
                  $mainCriteria->condition=' (col1,col2,col3) in ('.$subQuery.') ';
                  $mainCriteria->order = 'col1,col2,col3';
                  

                  使用方法:

                  $result = MyModel::model()->findAll($mainCriteria);
                  

                  或者:

                  $dataProvider = new CActiveDataProvider('MyModel', array(
                          'criteria'=>$mainCriteria,
                  ));
                  

                  来源:http://www.yiiframework.com/wiki/364/using-sub-query-for-doubletts/

                  这篇关于子查询 ActiveRecord Yii的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Is PHP or PHP based web framework stateful or stateless?(PHP 或基于 PHP 的 Web 框架是有状态的还是无状态的?)
                  How to parse django style template tags(如何解析 django 样式模板标签)
                  What is a good setup for editing PHP in Emacs?(在 Emacs 中编辑 PHP 的好设置是什么?)
                  How to check whether specified PID is currently running without invoking ps from PHP?(如何在不从 PHP 调用 ps 的情况下检查指定的 PID 当前是否正在运行?)
                  What#39;s the difference between escapeshellarg and escapeshellcmd?(escapeshellarg 和escapeshellcmd 有什么区别?)
                  php in background exec() function(php 后台 exec() 函数)
                      <tbody id='G5ZYC'></tbody>
                    • <bdo id='G5ZYC'></bdo><ul id='G5ZYC'></ul>

                        <legend id='G5ZYC'><style id='G5ZYC'><dir id='G5ZYC'><q id='G5ZYC'></q></dir></style></legend>

                        <small id='G5ZYC'></small><noframes id='G5ZYC'>

                        <tfoot id='G5ZYC'></tfoot>

                        <i id='G5ZYC'><tr id='G5ZYC'><dt id='G5ZYC'><q id='G5ZYC'><span id='G5ZYC'><b id='G5ZYC'><form id='G5ZYC'><ins id='G5ZYC'></ins><ul id='G5ZYC'></ul><sub id='G5ZYC'></sub></form><legend id='G5ZYC'></legend><bdo id='G5ZYC'><pre id='G5ZYC'><center id='G5ZYC'></center></pre></bdo></b><th id='G5ZYC'></th></span></q></dt></tr></i><div id='G5ZYC'><tfoot id='G5ZYC'></tfoot><dl id='G5ZYC'><fieldset id='G5ZYC'></fieldset></dl></div>