首页 > 后端开发 > php教程 > 这句mysql语句如何排先后呀

这句mysql语句如何排先后呀

WBOY
发布: 2016-06-13 10:28:27
原创
829 人浏览过

这句mysql语句怎么排先后呀?
SELECT * FROM text where (`title` like '%我们%' and `title` like '%他们%') or (`title` like '%我们%' or `title` like '%他们%') limit 6

有办法先把前一个条件的(`title` like '%我们%' and `title` like '%他们%')列出来在列出后面条件的吗?

------解决方案--------------------
试试这样?

SQL code
SELECT *, ((`title` like '%我们%' and `title` like '%他们%') * 0.8 + (`title` like '%我们%' or `title` like '%他们%') * 0.2) AS relevanceFROM textWHERE (`title` like '%我们%' and `title` like '%他们%') or (`title` like '%我们%' or `title` like '%他们%') ORDER BY relevance DESClimit 6<br><font color="#e78608">------解决方案--------------------</font><br>
登录后复制
SQL code
SELECT * FROM (         SELECT * FROM `text` where `title` like '%我们%' and `title` like '%他们%') ttWHERE  `title` like '%我们%' or `title` like '%他们%' limit 6;<br><font color="#e78608">------解决方案--------------------</font><br>
登录后复制
SQL code
SELECT *, 1 as xh FROM text where (`title` like '%我们%' and `title` like '%他们%')unionSELECT *, 2 as xh FROM text where (`title` like '%我们%' or `title` like '%他们%')order by xhlimit 6<div class="clear">
                 
              
              
        
            </div>
登录后复制
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板