Write an SQL statement. The Table companyid & nbsp; is edited from xuz0917 to 2013-04-1415: 29: 26; & nbsp; city & nbsp; & n write an SQL statement
At the end of this post, xuz0917 edited the table company at 15:29:26.
Id city top
1 Beijing, Shanghai Beijing
2 Jinan, Shijiazhuang Jinan
3 Beijing
Sorting rules:
1. search "Beijing" to list "Beijing" in "city;
2. there is "Beijing's top" in the 'top ";
3. sort SQL mysql SQL statements from large to small by 'id'
------ Solution --------------------
Select * from company where city like '% Beijing %' and top like 'Beijing' order by id desc union select * from company where city like '% Beijing %' and top not like' beijing 'Order by id desc
------ Solution --------------------
Select * from company where city like '% Beijing %' and top like 'Beijing' order by id desc union select * from company where city like '% Beijing %' and top not like' beijing 'Order by id desc
------ Solution --------------------
Try this. the test is acceptable.
SELECT *
FROM test
WHERE city LIKE '% Beijing %'
Order (
Top LIKE '% Beijing %'
) DESC, id DESC