求写一SQL语句

WBOY
Libérer: 2016-06-23 14:05:47
original
763 Les gens l'ont consulté

表company
id      city            top                
1       北京,上海       北京
2       济南,石家庄     济南
3       北京            北京

排序规则:
1、搜索“北京”列出`city`中有“北京”的;
2、`top`中有“北京的靠前”;
3、`id`从大到小排列


回复讨论(解决方案)

再加50分,就这些分了,请大哥大姐帮忙

不够100分了,请大哥大姐帮忙

不在线等了,想拿分的找我QQ515403255


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

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 
Copier après la connexion

这个好像不是我想要的

试试这个,测试可以

SELECT *FROM testWHERE city LIKE '%北京%'ORDER BY (top LIKE '%北京%') DESC , id DESC
Copier après la connexion

表名没改,test改成company

试试这个,测试可以


SQL code
?



123456

SELECT * FROM test WHERE city LIKE '%北京%'ORDER BY ( top LIKE '%北京%') DESC , id DESC
正解

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
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
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!