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

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

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

        Mysql:按like排序?

        时间:2023-06-02

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

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

            • <bdo id='xbLUo'></bdo><ul id='xbLUo'></ul>
                <tbody id='xbLUo'></tbody>
              <legend id='xbLUo'><style id='xbLUo'><dir id='xbLUo'><q id='xbLUo'></q></dir></style></legend>

              <tfoot id='xbLUo'></tfoot>

                  本文介绍了Mysql:按like排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  假设我们使用关键字执行搜索:keyword1、keyword2、keyword3

                  数据库中有name"列的记录:

                  <前>1:约翰·多伊2:塞缪尔·多伊3:约翰史密斯4:安娜史密斯

                  现在查询:

                  SELECT * FROM users WHERE (name LIKE "%John%" OR name LIKE "%Doe%")

                  它将选择记录:1,2,3(按此顺序)但我想按关键字订购例如 keyword1=John, keyword2=Doe所以应该按关键字列出:1,3,2(因为我想在搜索John"后搜索Doe")

                  我在考虑 SELECT DISTINCT FROM (...... UNION .....)但是以另一种方式对其进行排序会容易得多(真正的查询很长)

                  有什么技巧可以创建这样的订单吗?

                  解决方案

                  order by case当名字 LIKE "%John%" 然后 1当名称 LIKE "%Doe%" 然后 2其他 3结尾

                  assume that we are performing search using keywords: keyword1, keyword2, keyword3

                  there are records in database with column "name":

                  1: John Doe
                  2: Samuel Doe
                  3: John Smith
                  4: Anna Smith
                  

                  now Query:

                  SELECT * FROM users WHERE (name LIKE "%John%" OR name LIKE "%Doe%")
                  

                  it will select records: 1,2,3 (in this order) but i want to order it by keyword in example keyword1=John, keyword2=Doe so it should be listed by keywords: 1,3,2 (because i want to perform search for "Doe" after searching for "John")

                  I was thinking about SELECT DISTINCT FROM (...... UNION .....) but it will be much easier to order it somehow in another way (real query is really long)

                  are there any tricks to create such order?

                  解决方案

                  order by case 
                      when name LIKE "%John%" then 1 
                      when name LIKE "%Doe%"  then 2 
                      else 3 
                  end
                  

                  这篇关于Mysql:按like排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:从 .frm 文件恢复 mysql 数据库 下一篇:mysql - 多少列太多了?

                  相关文章

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

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

                  2. <tfoot id='S1wE1'></tfoot>
                      <bdo id='S1wE1'></bdo><ul id='S1wE1'></ul>