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

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

      1. <tfoot id='Hov4d'></tfoot>
        <legend id='Hov4d'><style id='Hov4d'><dir id='Hov4d'><q id='Hov4d'></q></dir></style></legend>
      2. MySQL:选择语句中的自动增量临时列

        时间:2023-07-17

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

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

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

                  本文介绍了MySQL:选择语句中的自动增量临时列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何在 MySQL 的 select 语句中创建和自动增加一个临时列?

                  这是我目前所拥有的:

                  SET @cnt = 0;选择(@cnt =@cnt + 1) AS rowNumber,行号从我的表类别 ID = 1

                  返回:

                  +++++++++++++++++++++++ 行号 |行号 +++++++++++++++++++++++++ (NULL) |1 ++ (NULL) |25 ++ (NULL) |33 ++ (NULL) |150++ (NULL) |219 ++++++++++++++++++++++++

                  但我需要:

                  +++++++++++++++++++++++ 行号 |行号 +++++++++++++++++++++++++ 1 |1 ++ 2 |25 ++ 3 |33 ++ 4 |150++ ... |... ++++++++++++++++++++++++

                  解决方案

                  这会给你一个连续行号和3.

                  SELECT(@cnt := @cnt + 1) AS rowNumber,行号从 myTable AS tCROSS JOIN (SELECT @cnt := 0) AS 虚拟哪里 t.CategoryID = 1按 t.rowID 排序;

                  结果

                  <前>|行号 |行列 |---------------------|1 |1 ||2 |25 ||3 |33 ||4 |150 |

                  How do I create and auto increment a temporary column in my select statement with MySQL?

                  Here is what I have so far:

                  SET @cnt = 0;
                  SELECT
                      (@cnt =@cnt + 1) AS rowNumber,
                      rowID
                  FROM myTable
                  WHERE CategoryID = 1
                  

                  Which returns:

                  +++++++++++++++++++++
                  + rowNumber | rowID +
                  +++++++++++++++++++++
                  +  (NULL)   |   1   +
                  +  (NULL)   |   25  +
                  +  (NULL)   |   33  +
                  +  (NULL)   |   150 +
                  +  (NULL)   |   219 +
                  +++++++++++++++++++++
                  

                  But I need:

                  +++++++++++++++++++++
                  + rowNumber | rowID +
                  +++++++++++++++++++++
                  +  1        |   1   +
                  +  2        |   25  +
                  +  3        |   33  +
                  +  4        |   150 +
                  +  ...      |   ... +
                  +++++++++++++++++++++
                  

                  解决方案

                  This will give you a consecutive row number with 3.

                  SELECT
                      (@cnt := @cnt + 1) AS rowNumber,
                      t.rowID
                  FROM myTable AS t
                    CROSS JOIN (SELECT @cnt := 0) AS dummy
                  WHERE t.CategoryID = 1
                  ORDER BY t.rowID ;
                  

                  Result

                  | ROWNUMBER | ROWID |
                  ---------------------
                  |         1 |     1 |
                  |         2 |    25 |
                  |         3 |    33 |
                  |         4 |   150 |

                  这篇关于MySQL:选择语句中的自动增量临时列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在表 MYSQL 的子集中自动递增 下一篇:自增唯一标识符

                  相关文章

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

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

                    1. <legend id='ZLSh3'><style id='ZLSh3'><dir id='ZLSh3'><q id='ZLSh3'></q></dir></style></legend>