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

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

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

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

          <bdo id='pZMYj'></bdo><ul id='pZMYj'></ul>
      1. 带有子查询的mysql更新查询

        时间:2023-06-26
            <tbody id='vxBsU'></tbody>
          <legend id='vxBsU'><style id='vxBsU'><dir id='vxBsU'><q id='vxBsU'></q></dir></style></legend>

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

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

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

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

                  问题描述

                  谁能看出下面的查询有什么问题?

                  Can anyone see what is wrong with the below query?

                  当我运行它时,我得到:

                  When I run it I get:

                  #1064 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册以了解要使用的正确语法在第 8 行的a where a.CompetitionID = Competition.CompetitionID"附近

                  #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'a where a.CompetitionID = Competition.CompetitionID' at line 8

                  Update Competition
                  Set Competition.NumberOfTeams =
                  (
                  SELECT count(*) as NumberOfTeams
                  FROM PicksPoints
                  where UserCompetitionID is not NULL
                  group by CompetitionID
                  ) a
                  where a.CompetitionID =  Competition.CompetitionID
                  

                  推荐答案

                  主要问题是内部查询不能与外部 update 上的 where 子句相关语句,因为 where 过滤器首先应用于正在更新的表,甚至在内部子查询执行之前.处理这种情况的典型方法是多表更新.

                  The main issue is that the inner query cannot be related to your where clause on the outer update statement, because the where filter applies first to the table being updated before the inner subquery even executes. The typical way to handle a situation like this is a multi-table update.

                  Update
                    Competition as C
                    inner join (
                      select CompetitionId, count(*) as NumberOfTeams
                      from PicksPoints as p
                      where UserCompetitionID is not NULL
                      group by CompetitionID
                    ) as A on C.CompetitionID = A.CompetitionID
                  set C.NumberOfTeams = A.NumberOfTeams
                  

                  演示:http://www.sqlfiddle.com/#!2/a74f3/1

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

                  上一篇:索引布尔字段是否有任何性能提升? 下一篇:MySQL:GROUP_CONCAT 与 LEFT JOIN

                  相关文章

                  <tfoot id='ftEZf'></tfoot>

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

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