Write an SQL statement

Source: Internet
Author: User
Write an SQL statement table "company"
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. arrange 'id' from large to small


Reply to discussion (solution)

50 more points. that's all. please help me.

Less than 100 points. please help me

Don't wait online. if you want to get the score, contact me for the 15403255


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

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

This is not what I want.

Try this. the test is acceptable.

SELECT * FROM testWHERE city LIKE '% Beijing %' order by (top LIKE '% Beijing %') DESC, id DESC

The table name is not changed. change test to company.

Try this. the test is acceptable.


SQL code
?



123456

SELECT * FROM test WHERE city LIKE '% Beijing %' order by (top LIKE '% Beijing %') DESC, id DESC
Positive solution

Related Article

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.