• <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. 自动递增 - 每年自动重置

        Auto-increment - automatic reset for each year(自动递增 - 每年自动重置)
        <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;
                  

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

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Simulating group_concat MySQL function in Microsoft SQL Server 2005?(在 Microsoft SQL Server 2005 中模拟 group_concat MySQL 函数?)
                  MySQL Auto Increment Custom Values(MySQL 自动递增自定义值)
                  Change the step auto_increment fields increment by(更改步骤 auto_increment 字段增量)
                  How to return the value of AUTO INCREMENT column in SQLite with VB6(如何使用 VB6 在 SQLite 中返回 AUTO INCREMENT 列的值)
                  How to insert new row to database with AUTO_INCREMENT column without specifying column names?(如何在不指定列名的情况下使用 AUTO_INCREMENT 列将新行插入到数据库中?)
                  Mysql - Add auto_increment to primary key(Mysql - 将 auto_increment 添加到主键)

                      • <bdo id='u0CMo'></bdo><ul id='u0CMo'></ul>
                        • <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>
                              <tbody id='u0CMo'></tbody>