• <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排序?

        Mysql: Order by like?(Mysql:按like排序?)

        <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排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Bogus foreign key constraint fail(虚假外键约束失败)
                  how to get last insert id after insert query in codeigniter active record(如何在codeigniter活动记录中插入查询后获取最后一个插入ID)
                  Force InnoDB to recheck foreign keys on a table/tables?(强制 InnoDB 重新检查表/表上的外键?)
                  How to auto generate migrations with Sequelize CLI from Sequelize models?(如何使用 Sequelize CLI 从 Sequelize 模型自动生成迁移?)
                  Clear MySQL query cache without restarting server(无需重启服务器即可清除 MySQL 查询缓存)
                  ALTER TABLE to add a composite primary key(ALTER TABLE 添加复合主键)
                  <legend id='S1wE1'><style id='S1wE1'><dir id='S1wE1'><q id='S1wE1'></q></dir></style></legend>
                    <tbody id='S1wE1'></tbody>
                    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'>

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