这句mysql语句如何排先后呀

WBOY
Lepaskan: 2016-06-13 13:27:03
asal
850 orang telah melayarinya

这句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>
Salin selepas log masuk
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>
Salin selepas log masuk
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>
Salin selepas log masuk
Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan