1. <small id='JThSJ'></small><noframes id='JThSJ'>

        <bdo id='JThSJ'></bdo><ul id='JThSJ'></ul>
    2. <legend id='JThSJ'><style id='JThSJ'><dir id='JThSJ'><q id='JThSJ'></q></dir></style></legend>
    3. <tfoot id='JThSJ'></tfoot>
      1. <i id='JThSJ'><tr id='JThSJ'><dt id='JThSJ'><q id='JThSJ'><span id='JThSJ'><b id='JThSJ'><form id='JThSJ'><ins id='JThSJ'></ins><ul id='JThSJ'></ul><sub id='JThSJ'></sub></form><legend id='JThSJ'></legend><bdo id='JThSJ'><pre id='JThSJ'><center id='JThSJ'></center></pre></bdo></b><th id='JThSJ'></th></span></q></dt></tr></i><div id='JThSJ'><tfoot id='JThSJ'></tfoot><dl id='JThSJ'><fieldset id='JThSJ'></fieldset></dl></div>
      2. yii2 ActiveRecord 使用计算查找 OrderBy

        时间:2023-10-15
      3. <small id='qa1Ax'></small><noframes id='qa1Ax'>

          <tbody id='qa1Ax'></tbody>
          <bdo id='qa1Ax'></bdo><ul id='qa1Ax'></ul>

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

                  本文介绍了yii2 ActiveRecord 使用计算查找 OrderBy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  试图从我的数据库中获取描述.查询返回结果,但我想将结果排序为只显示投票最高的那个.

                  Trying to fetch a description from my database. The query returns the result but I would like to order the result to only show the one with the highest vote.

                  投票应该由upvoted列减去downvoted

                  $description = UnitDescription::find()
                     ->where(['id_unit' => $model->id])
                     ->orderBy([
                        'upvoted - downvoted' => SORT_DESC //Need this line to be fixed
                     ])
                     ->one();
                  

                  我希望有人可以编写查询的这一部分 - 谢谢

                  I was hoping someone might have a way to write this part of the query - Thanks

                  推荐答案

                  你应该简单地尝试:

                  $description = UnitDescription::find()
                      ->where(['id_unit' => $model->id])
                      ->orderBy(['(upvoted - downvoted)' => SORT_DESC])
                      ->one();
                  

                  这篇关于yii2 ActiveRecord 使用计算查找 OrderBy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:YII2 gridview对两列值的总和进行排序 下一篇:PHPStorm 中未定义的类 DateTime

                  相关文章

                      <bdo id='TaqvQ'></bdo><ul id='TaqvQ'></ul>

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

                    1. <small id='TaqvQ'></small><noframes id='TaqvQ'>

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