• <bdo id='WnbkY'></bdo><ul id='WnbkY'></ul>

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

      <tfoot id='WnbkY'></tfoot>

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

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

      1. 如何在 zend db 上构建嵌套选择

        时间:2023-06-06
              <tbody id='12m7A'></tbody>

            <small id='12m7A'></small><noframes id='12m7A'>

              <bdo id='12m7A'></bdo><ul id='12m7A'></ul>
              • <legend id='12m7A'><style id='12m7A'><dir id='12m7A'><q id='12m7A'></q></dir></style></legend>
                  <tfoot id='12m7A'></tfoot>

                  <i id='12m7A'><tr id='12m7A'><dt id='12m7A'><q id='12m7A'><span id='12m7A'><b id='12m7A'><form id='12m7A'><ins id='12m7A'></ins><ul id='12m7A'></ul><sub id='12m7A'></sub></form><legend id='12m7A'></legend><bdo id='12m7A'><pre id='12m7A'><center id='12m7A'></center></pre></bdo></b><th id='12m7A'></th></span></q></dt></tr></i><div id='12m7A'><tfoot id='12m7A'></tfoot><dl id='12m7A'><fieldset id='12m7A'></fieldset></dl></div>
                1. 本文介绍了如何在 zend db 上构建嵌套选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  这个查询有问题

                  SELECT * FROM(
                      SELECT `b`.*,`owner`.firstname,`owner`.lastname,`owner`.email,
                      (
                          SELECT COUNT(`ps`.profile_id)   FROM `profile` AS `ps`
                          LEFT JOIN `xref_store_profile_brand` AS `xbp` ON `xbp`.profile_id = `ps`.profile_id
                          WHERE `xbp`.brand_id = b.brand_id AND ps.role = 'salesrep' AND `xbp`.store_id IS NULL
                      ) AS `salesrepTotal`,
                      (
                          SELECT GROUP_CONCAT(`ms`.firstname)   FROM `profile` AS `ps`
                          LEFT JOIN `xref_store_profile_brand` AS `xbp` ON `xbp`.profile_id = `ps`.profile_id
                          LEFT JOIN `member` AS `ms`ON `ms`.member_id = `ps`.member_id
                          WHERE `xbp`.brand_id = `b`.brand_id AND ps.role = 'salesrep' AND `xbp`.store_id IS NULL
                      ) AS `salesrep`,
                      (
                          SELECT COUNT(`s`.store_id) FROM `store` AS `s`
                          LEFT JOIN `xref_store_profile_brand` AS `xbs` ON `xbs`.store_id = `s`.store_id
                          WHERE `xbs`.brand_id = `b`.brand_id AND `xbs`.brand_id IS NOT NULL
                      ) AS `storeTotal`,
                      (
                          SELECT GROUP_CONCAT(`s`.name) FROM `store` AS `s`
                          LEFT JOIN `xref_store_profile_brand` AS `xbs` ON `xbs`.store_id = `s`.store_id
                          WHERE `xbs`.brand_id = `b`.brand_id AND `xbs`.brand_id IS NOT NULL
                      ) AS `store`
                  
                      FROM `brand` AS `b`
                      LEFT JOIN
                      (
                          SELECT `m`.firstname,`m`.lastname,`m`.email,`xspb`.brand_id FROM `member` AS `m`
                          LEFT JOIN `profile` as `p` ON `p`.member_id = `m`.member_id AND `p`.role = 'designer' AND `p`.isPrimary = 1
                          LEFT JOIN `xref_store_profile_brand` AS `xspb` ON `xspb`.profile_id = `p`.profile_id AND `xspb`.store_id IS NULL
                      ) AS `owner` ON `owner`.brand_id =`b`.brand_id
                  
                      GROUP BY `b`.brand_id
                  ) AS `final`
                  

                  如何将其转换为 Zend_Db_Select 对象?

                  how can i convert this in to Zend_Db_Select object?

                  主要问题是这部分

                  SELECT `b`.*,`owner`.firstname,`owner`.lastname,`owner`.email,
                      (
                          SELECT COUNT(`ps`.profile_id)   FROM `profile` AS `ps`
                          LEFT JOIN `xref_store_profile_brand` AS `xbp` ON `xbp`.profile_id = `ps`.profile_id
                          WHERE `xbp`.brand_id = b.brand_id AND ps.role = 'salesrep' AND `xbp`.store_id IS NULL
                      ) AS `salesrepTotal`,
                  

                  推荐答案

                  您需要使用 Zend_Db_Expr 对象在您的查询和 选择 AS 的数组结构.

                  You need to use Zend_Db_Expr objects in your query and array structures for select AS.

                  以下是您正在寻找的解决方案:

                  below is the solution you are looking for:

                  <?php
                  
                  $db = Zend_Db_Table::getDefaultAdapter();
                  
                  //  inner query
                  $sqlSalesRepTotal = $db->select()
                          ->from(array('ps' => 'profile'))
                          ->joinLeft(array('xbp' => 'xref_store_profile_brand'), 'xbp.profile_id = ps.profile_id')
                          ->where('xbp.brand_id = b.brand_id')
                          ->where('ps.role = ?', 'salesrep')
                          ->where('xbp.store_id IS NULL');
                  
                  //  main query
                  $sql = $db->select()
                          ->from(array('b' => 'brand'), array(
                              //  NOTE: have to add parentesis around the expression
                              'salesrepTotal' => new Zend_Db_Expr("($sqlSalesRepTotal)")
                          ))
                          ->where('....')
                          ->group('brand_id');
                  
                  
                  //  debug
                  var_dump($db->fetchAll($sql));
                  

                  这篇关于如何在 zend db 上构建嵌套选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在 *nix 上将 Zend Framework 2 与 MS SQL Server 一起 下一篇:ODP.Net 驱动程序在 .NET Core 5.0 上抛出异常

                  相关文章

                  最新文章

                  1. <tfoot id='FPPQV'></tfoot>

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

                    1. <legend id='FPPQV'><style id='FPPQV'><dir id='FPPQV'><q id='FPPQV'></q></dir></style></legend>
                        <bdo id='FPPQV'></bdo><ul id='FPPQV'></ul>

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