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

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

    • <bdo id='GtT59'></bdo><ul id='GtT59'></ul>

      <tfoot id='GtT59'></tfoot>
    1. <small id='GtT59'></small><noframes id='GtT59'>

        按以数字开头的字符串排序 - ActiveRecord

        时间:2023-06-06

            <bdo id='QlE7f'></bdo><ul id='QlE7f'></ul>
            <tfoot id='QlE7f'></tfoot>

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

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

                • 本文介绍了按以数字开头的字符串排序 - ActiveRecord的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我正在构建 Rails 应用程序并尝试按以数字开头的字符串列对数据库中的记录进行排序.
                  怎么先按号码下单?
                  我宁愿按 SQL 顺序排序,也不愿按 ruby​​ 方法排序.有什么办法吗?

                  I'm building Rails app and trying to order records in database by string column that starts with number.
                  How can I order by the number at first?
                  I'd rather ordering as SQL order than sorting by ruby method. Is there any way?

                  expected order
                  1.record1
                  2.record2
                  10.record10
                  

                  present order
                  1.record1
                  10.record10
                  2.record2
                  

                  推荐答案

                  您可以order by field + 0 改变field的数据类型code> 隐式转换为一个数字:

                  You could order by field + 0 to change the data type of field to a number implicitly:

                  Model.order("field + 0 ASC")
                  
                  # similar `string`.to_i in Ruby
                  # `1.record1`   => 1
                  # `10.record10` => 10
                  

                  这篇关于按以数字开头的字符串排序 - ActiveRecord的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:ADO.NET - 使用应用程序提供的登录名和密码通过 下一篇:在 Rails 中使用特定的 mysql 索引

                  相关文章

                  最新文章

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

                    • <bdo id='QlNS1'></bdo><ul id='QlNS1'></ul>

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

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