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

        <legend id='kt3Ks'><style id='kt3Ks'><dir id='kt3Ks'><q id='kt3Ks'></q></dir></style></legend><tfoot id='kt3Ks'></tfoot>
          <bdo id='kt3Ks'></bdo><ul id='kt3Ks'></ul>

        我如何存储订单?

        时间:2023-11-28

            • <small id='8qhko'></small><noframes id='8qhko'>

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

                • 本文介绍了我如何存储订单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个包含任务的应用程序,您可以对它们重新排序.现在我正在考虑如何最好地储存它们.我是否应该为订单号设置一个列并在每次更改时重新计算所有这些?请告诉我一个不需要我更新所有订单号的版本,因为这非常耗时(从执行的角度来看).

                  I have an app which has tasks in it and you can reorder them. Now I was woundering how to best store them. Should I have a colomn for the ordernumber and recalculate all of them everytime I change one? Please tell me a version which doesn't require me to update all order numbers since that is very time consuming (from the executions point of view).

                  如果我必须把最上面的一个放在订单的顶部,然后把它拖到底部,这尤其糟糕.

                  This is especially bad if I have to put one that is at the very top of the order and then drag it down to the bottom.

                  • 姓名(订单号)

                  --

                  • 1例(1)
                  • 2例(2)
                  • 3例(3)
                  • 4例(4)
                  • 5例(5)

                  --

                  • 2例 (1) *
                  • 3例 (2) *
                  • 4例(3)*
                  • 5例(4)*
                  • 1例 (5) *

                  *必须在数据库中更改

                  还有一些任务可能会因为完成而被删除

                  also some tasks may get deleted due to them being done

                  推荐答案

                  您可以将订单保留为文字,并使用词法排序:

                  You may keep orders as literals, and use lexical sort:

                  1. A
                  2. Z
                  

                  添加任务:

                  1. A
                  3. L
                  2. Z
                  

                  添加更多:

                  1. A
                  4. B
                  3. L
                  2. Z
                  

                  在 1 和 4 之间移动 2:

                  Move 2 between 1 and 4:

                  1. A
                  2. AL
                  4. B
                  3. L
                  

                  您一次只更新一条记录:只需在第一个不同的记录之间取一个平均字母:如果您在 AC 之间放置,则取 B,如果你在ALGJALILFG 之间,你取ALH.

                  You update only one record at a time: just take an average letter between the first ones that differ: if you put between A and C, you take B, if you put between ALGJ and ALILFG, you take ALH.

                  现有的字母旁边的字母算作现有的与 Z 旁边的字母连接.IE.如果需要放在ABHDFGACSDF之间,则算在ABHAB(Z+)之间,并写出AB(letter 35/2),即ABP.

                  Letter next to existing counts as existing concatenated with the one next to Z. I. e. if you need put between ABHDFG and ACSDF, you count it as between ABH and AB(Z+), and write AB(letter 35/2), that is ABP.

                  如果字符串长度用完,您可能总是执行完整的重新排序.

                  If you run out of string length, you may always perform a full reorder.

                  更新:

                  您也可以将数据保存为链接列表.

                  You can also keep your data as a linked list.

                  请参阅我博客中有关如何在 MySQL 中执行此操作的文章:

                  See the article in my blog on how to do it in MySQL:

                  • 排序列表

                  简而言之:

                  /* This just returns all records in no particular order */
                  
                  SELECT  *
                  FROM    t_list
                  
                  id      parent
                  ------- --------
                  1       0
                  2       3
                  3       4
                  4       1
                  
                  /* This returns all records in intended order */
                  
                  SELECT  @r AS _current,
                          @r := (
                          SELECT  id
                          FROM    t_list
                          WHERE   parent = _current
                          )
                  FROM    (
                          SELECT  @r := 0
                          ) vars,
                          t_list
                  
                  _current id
                  -------  --------
                  0        1
                  1        4
                  4        3
                  3        2
                  

                  移动项目时,您最多需要更新 4 行.

                  When moving the items, you'll need to update at most 4 rows.

                  这似乎是保持经常更新的有序列表的最有效方法.

                  This seems to be the most efficient way to keep an ordered list that is updated frequently.

                  这篇关于我如何存储订单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:什么是索引以及如何使用它们来优化数据库中的查询? 下一篇:与时间属性相关的设计数据库

                  相关文章

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

                    <tfoot id='RBo1b'></tfoot>