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

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

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

      2. 将行限制为一列总和等于 MySQL 中的某个值

        时间:2023-06-01
        <tfoot id='1KPCH'></tfoot>
          <tbody id='1KPCH'></tbody>
      3. <legend id='1KPCH'><style id='1KPCH'><dir id='1KPCH'><q id='1KPCH'></q></dir></style></legend>

        <small id='1KPCH'></small><noframes id='1KPCH'>

                <i id='1KPCH'><tr id='1KPCH'><dt id='1KPCH'><q id='1KPCH'><span id='1KPCH'><b id='1KPCH'><form id='1KPCH'><ins id='1KPCH'></ins><ul id='1KPCH'></ul><sub id='1KPCH'></sub></form><legend id='1KPCH'></legend><bdo id='1KPCH'><pre id='1KPCH'><center id='1KPCH'></center></pre></bdo></b><th id='1KPCH'></th></span></q></dt></tr></i><div id='1KPCH'><tfoot id='1KPCH'></tfoot><dl id='1KPCH'><fieldset id='1KPCH'></fieldset></dl></div>
                • <bdo id='1KPCH'></bdo><ul id='1KPCH'></ul>
                • 本文介绍了将行限制为一列总和等于 MySQL 中的某个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想编写一个查询,该查询返回所有行,直到其中一列值的总和达到某个值.

                  I want to write a query which returns all rows until the sum of one of the columns value reaches a certain value.

                  例如下表:

                             DATE             ETC      Meeting
                      2013-02-01 00:00:00    85482        1
                      2013-02-01 00:00:00    47228        2
                      2013-02-02 00:00:00    12026        4
                      2013-02-03 00:00:00    78927        6
                      2013-02-04 00:00:00    85662        2
                      2013-03-05 00:00:00    47978        1
                      2013-08-07 00:00:00     8582        1
                  

                  如果我想得到行,直到 Meeting 列的总和等于 7.

                  If I want to get the rows until the sum of column Meeting equals 7.

                             DATE             ETC      Meeting
                      2013-02-01 00:00:00    85482        1
                      2013-02-01 00:00:00    47228        2
                      2013-02-02 00:00:00    12026        4
                  

                  如果我想得到行,直到 Meeting 列的总和等于 13.

                  If I want to get the rows until the sum of column Meeting equals 13.

                       DATE                   ETC      Meeting
                      2013-02-01 00:00:00    85482        1
                      2013-02-01 00:00:00    47228        2
                      2013-02-02 00:00:00    12026        4
                      2013-02-03 00:00:00    78927        6
                  

                  推荐答案

                  这是一种应该在 MySQL 中工作的方法:

                  Here's a way which should work in MySQL :

                  SELECT
                    O.Id,
                    O.Type,
                    O.MyAmountCol,
                    (SELECT
                       sum(MyAmountCol) FROM Table1
                     WHERE Id <= O.Id) 'RunningTotal'
                  FROM Table1 O
                  HAVING RunningTotal <= 7
                  

                  它涉及计算运行总数并选择运行总数小于或等于给定数字的记录,在本例中为7.

                  It involves calculating a running total and selecting records while the running total is less than or equal to the given number, in this case 7.

                  这篇关于将行限制为一列总和等于 MySQL 中的某个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:VBA如何在Excel中连接MySQL数据库? 下一篇:删除重复的行只留下最旧的行?

                  相关文章

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

                    <tfoot id='zHY18'></tfoot>
                      <bdo id='zHY18'></bdo><ul id='zHY18'></ul>

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

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