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

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

        如何在sql server中获取一列的运行总和

        时间:2023-10-08
        • <bdo id='pAZ9R'></bdo><ul id='pAZ9R'></ul>
          <i id='pAZ9R'><tr id='pAZ9R'><dt id='pAZ9R'><q id='pAZ9R'><span id='pAZ9R'><b id='pAZ9R'><form id='pAZ9R'><ins id='pAZ9R'></ins><ul id='pAZ9R'></ul><sub id='pAZ9R'></sub></form><legend id='pAZ9R'></legend><bdo id='pAZ9R'><pre id='pAZ9R'><center id='pAZ9R'></center></pre></bdo></b><th id='pAZ9R'></th></span></q></dt></tr></i><div id='pAZ9R'><tfoot id='pAZ9R'></tfoot><dl id='pAZ9R'><fieldset id='pAZ9R'></fieldset></dl></div>

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

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

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

                    <tbody id='pAZ9R'></tbody>
                1. 本文介绍了如何在sql server中获取一列的运行总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在 Bills 表中有一个名为 Qty 的列我想要一个列显示 Qty 列的运行总和,如下所示:

                  Hi I have a column with name Qty from table Bills i want a column that show the running sum of Qty column like this :

                  Qty   Run_Sum
                  1      1
                  2      3
                  3      6
                  4      10
                  5      15
                  

                  建议我一些合适的方法来运行一些谢谢

                  Suggest me some appropriate method to make running some thankx

                  推荐答案

                  SQLFiddle demo

                  SELECT Qty,
                  SUM(Qty) OVER (ORDER BY Qty) Run_Sum
                  FROM t ORDER BY Qty
                  

                  对于 2012 年之前的 SQLServer:

                  For SQLServer prior to 2012:

                  select Qty,
                  (select sum(Qty) from t where Qty<=t1.Qty)
                  from t t1 order by Qty
                  

                  SQLFiddle 演示

                  或者你也可以不用子查询:

                  Or also you can do it without subquery:

                  select t1.Qty, sum(t2.Qty)
                  from t t1 
                  join t t2 on (t1.Qty>=t2.Qty)
                  group by t1.Qty
                  order by t1.Qty
                  

                  SQLFiddle 演示

                  这篇关于如何在sql server中获取一列的运行总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:MySQL select where 等于多个值 下一篇:此 SELECT 查询需要 180 秒才能完成

                  相关文章

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

                      <legend id='LDNB3'><style id='LDNB3'><dir id='LDNB3'><q id='LDNB3'></q></dir></style></legend>
                      <tfoot id='LDNB3'></tfoot>