>  기사  >  백엔드 개발  >  这句mysql语句如何排先后呀

这句mysql语句如何排先后呀

WBOY
WBOY원래의
2016-06-13 13:27:03815검색

这句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 relevance
FROM text
WHERE (`title` like '%我们%' and `title` like '%他们%') or (`title` like '%我们%' or `title` like '%他们%') 
ORDER BY relevance DESC
limit 6
<br><font color="#e78608">------解决方案--------------------</font><br>
SQL code
SELECT * FROM 
(
         SELECT * FROM `text` where `title` like '%我们%' and `title` like '%他们%'
) tt
WHERE  `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 '%他们%')
union
SELECT *, 2 as xh FROM text where (`title` like '%我们%' or `title` like '%他们%')
order by xh
limit 6 <div class="clear">
                 
              
              
        
            </div>
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.