Write 1 SQL statement

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.