Write 1SQL statements

Source: Internet
Author: User
Write an SQL statement
This post was last edited by xuz0917 on 2013-04-14 15:29:26

Table Company
ID City Top
1 Beijing, Shanghai, China
2 Jinan, Shijiazhuang, Jinan
3 Beijing Beijing

Sorting rules:
1, search "Beijing" List of ' city ' in the "Beijing";
2, ' top ' has "Beijing's front";
3. ' ID ' from large to small array sqlmysqlsql sort php


------Solution--------------------

SELECT * FROM company where city like '% Beijing% ' and top like ' Beijing ' ORDER by id DESC Union SELECT * from company where City Lik E '% Beijing% ' and top not like ' Beijing ' ORDER by id DESC
------Solution--------------------




------Solution--------------------
Try this, the test can
SELECT *
From Test
WHERE city like '% Beijing '
ORDER by (
Top like '% Beijing '
) desc, id desc
  • 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.