Maison  >  Article  >  développement back-end  >  求写1SQL语句

求写1SQL语句

WBOY
WBOYoriginal
2016-06-13 11:21:06875parcourir

求写一SQL语句

本帖最后由 xuz0917 于 2013-04-14 15:29:26 编辑 表company
id      city            top                
1       北京,上海       北京
2       济南,石家庄     济南
3       北京            北京

排序规则:
1、搜索“北京”列出`city`中有“北京”的;
2、`top`中有“北京的靠前”;
3、`id`从大到小排列
SQL mysql sql排序 php
------解决方案--------------------

select * from company where city like '%北京%' and top like '北京' order by id desc union select * from company where city like '%北京%' and top not like '北京' order by id desc
------解决方案--------------------
<br />select * from company where city like '%北京%' and top like '北京' order by id desc union select * from company where city like '%北京%' and top not like '北京' order by id desc <br />

------解决方案--------------------
试试这个,测试可以
SELECT *<br />FROM test<br />WHERE city LIKE '%北京%'<br />ORDER BY (<br />top LIKE '%北京%'<br />) DESC , id DESC<br />
Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn