<bdo id='QkdUQ'></bdo><ul id='QkdUQ'></ul>
    <legend id='QkdUQ'><style id='QkdUQ'><dir id='QkdUQ'><q id='QkdUQ'></q></dir></style></legend>

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

    <tfoot id='QkdUQ'></tfoot>

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

        使用 Zend DB 编写子查询

        Writing a subquery using Zend DB(使用 Zend DB 编写子查询)
          <bdo id='fKeA4'></bdo><ul id='fKeA4'></ul>

            • <legend id='fKeA4'><style id='fKeA4'><dir id='fKeA4'><q id='fKeA4'></q></dir></style></legend>
                <tbody id='fKeA4'></tbody>

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

                  <tfoot id='fKeA4'></tfoot>
                  本文介绍了使用 Zend DB 编写子查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在将下面的 SQL 转换为 Zend Db 查询时遇到了一些问题.

                  I am having some problems turning the SQL below into a Zend Db query.

                  $select = ' SELECT s.id, i.id as instance_id, i.reference, i.name, i.sic_code, i.start_date
                                  FROM sles s
                                  JOIN sle_instances i
                                  ON s.id = i.sle_id
                                  WHERE i.id = (  SELECT MAX(id) 
                                                  FROM sle_instances 
                                                  WHERE sle_id = s.id
                                                  )
                                  ORDER BY i.name ASC';
                  

                  我已经了解了之前的代码 - 但是 Zend Db 没有正确生成查询.谁能告诉我我错过了什么??

                  I have got as far as the code before - but Zend Db isn't producing the query correctly. Can any one show me what I missing??

                  $select = $db->select() ->from('sles', array(   'id',
                                                                  'instance_id'   => 'sle_instances.id',                                                                                          
                                                                  'reference'     => 'sle_instances.reference',           
                                                                  'name'          => 'sle_instances.name',
                                                                  'sic_code'      => 'sle_instances.sic_code',
                                                                  'start_date'    => 'sle_instances.start_date'
                                                               )
                                                )
                                          ->join('sle_instances', 'sles.id = sle_instances.sle_id')
                                          ->where('sles.id = (SELECT MAX(id) FROM sle_instances WHERE sle_id = sles.id)')
                                          ->order('sle_instances.name ASC');
                  

                  顺便说一下,SQL 确实有效.我正在使用 Zend Db 重写它,因为我希望使用 Zend Paginator 功能.

                  The SQL does work by the way. I am rewriting it using Zend Db as I wish to use the Zend Paginator functionality.

                  非常感谢任何帮助.

                  PJ

                  推荐答案

                  这个:

                      $select = $db->select()->from(array("s" => "sles"), array("s.id","i.id as instanceid","i.reference","i.name","i.sic_code","i.start_date"))
                                                   ->join(array('i' => "sle_instances"),"s.id = i.sle_id",array())
                                                   ->where("i.id = (select max(id) from sle_instances where sle_id = s.id)")
                                                   ->order('i.name asc');
                  

                  给出这个:

                  "SELECT `s`.`id`, `i`.`id` AS `instanceid`, `i`.`reference`, `i`.`name`, `i`.`sic_code`, `i`.`start_date` FROM `sles` AS `s`
                   INNER JOIN `sle_instances` AS `i` ON s.id = i.sle_id WHERE (i.id = (select max(id) from sle_instances where sle_id = s.id)) ORDER BY `i`.`name` asc"
                  

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

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

                  相关文档推荐

                  SQL query to group by day(按天分组的 SQL 查询)
                  What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                  MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                  MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                  Include missing months in Group By query(在 Group By 查询中包含缺失的月份)
                  Why Mysql#39;s Group By and Oracle#39;s Group by behaviours are different(为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同)

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

                        <tbody id='jNCke'></tbody>
                      • <legend id='jNCke'><style id='jNCke'><dir id='jNCke'><q id='jNCke'></q></dir></style></legend>
                        <tfoot id='jNCke'></tfoot>
                            <bdo id='jNCke'></bdo><ul id='jNCke'></ul>

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