• <bdo id='3MNTV'></bdo><ul id='3MNTV'></ul>

    <small id='3MNTV'></small><noframes id='3MNTV'>

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

      1. 自动递增 - 每年自动重置

        时间:2023-07-18
        <tfoot id='AWwnk'></tfoot>

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

          • <legend id='AWwnk'><style id='AWwnk'><dir id='AWwnk'><q id='AWwnk'></q></dir></style></legend>

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

                    <tbody id='AWwnk'></tbody>
                  本文介绍了自动递增 - 每年自动重置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  MySQL/InnoDB

                  MySQL/InnoDB

                  就我而言,我的收据应按年计算;1/2015、2/2015 ... 556/2015 等等.明年来的时候,柜台要重新从1开始,收据应该算为1/2016, 2/2016 ...

                  In my case my receipts should be counted on yearly basis; 1/2015, 2/2015 ... 556/2015 and so on. When next year comes, the counter should start from 1 again and receipts should be counted as 1/2016, 2/2016 ...

                  如何定义每年自动重置的 auto_increment 字段?

                  How to define auto_increment field which will reset itself on yearly basis?

                  RCID | RCNO | RCYEAR | ...
                  =====+======+========+====
                   200 |    1 |   2015 |
                   201 |    2 |   2015 |
                   ... |  ... |   2015 |     
                   756 |  556 |   2015 |     <- last receipt in 2015
                   757 |    1 |   2016 |     <- yearly counter restarted
                  

                  注意:RCID 是标准的 PK 自动递增字段.

                  NOTE: RCID is standard PK auto incremented field.

                  推荐答案

                  在@RickJames 的帮助下,解决方案是:

                  After help from @RickJames the solution is:

                  CREATE TRIGGER ReceiptNumber BEFORE INSERT ON receipts FOR EACH ROW
                  BEGIN
                    SET NEW.rcyear=YEAR(NOW());
                    SET NEW.rcno=(SELECT IFNULL(MAX(rcno),0)+1 FROM receipts WHERE rcyear=YEAR(NOW()));
                  END;
                  

                  这篇关于自动递增 - 每年自动重置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:MySQL 自动递增自定义值 下一篇:无法创建表;为什么这段代码会失败?

                  相关文章

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

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

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