Mysql so can a sentence SQL come out?

Source: Internet
Author: User
Mysql so can you come out with a sentence of SQL?
--PhpMyAdmin SQL Dump
--Version 2.10.2
--Http://www.phpmyadmin.net
--
--Host: localhost
--Date of generation: January 25, 2013 06:32
--Server version: 5.0.45
--PHP version: 5.2.3

SET sql_mode= "No_auto_value_on_zero";

--
--Database: ' Test '
--

-- --------------------

--
--The structure of the table ' location '
--

CREATE TABLE ' Location ' (
' location_id ' int (ten) unsigned not NULL,
' Score ' int (ten) unsigned not NULL,
' Welcome ' tinyint (3) unsigned not NULL,
PRIMARY KEY (' location_id ')
) Engine=myisam DEFAULT CHARSET=GBK;

--
--Export the data in the table ' location '
--

INSERT into ' location ' VALUES (1000, 50, 1);
INSERT into ' location ' VALUES (1001, 60, 0);
INSERT into ' location ' VALUES (1002, 30, 1);
INSERT into ' location ' VALUES (1003, 20, 0);



Sorting requirements:
If welcome is 1, press score + 50来 row
Example query two data press score DESC
Result is
LOCATION_ID of two data for 1000 and 1002

Thanks for help!
MySQL


------Solution--------------------
Citation :
quote: Unclear expression!
Are you going to put welcome in front of 1?

SELECT * from location ORDER BY welcome=1 DESC, score desc

The moderator is like this
I would like to welcome=1 the score + 50, and then press score reverse order to row. The precondition is not to change the value of the original table.

Write like this
Select location_id, if (Welcome=1,score+50,score) as score, welcome from location ORDER BY score DESC


Array
(
[0] = = Array
(
[LOCATION_ID] = 1000
[Score] = 100
[Welcome] = 1
)

[1] = = Array
(
[LOCATION_ID] = 1002
[Score] = 80
[Welcome] = 1
)

[2] = = Array
(
[LOCATION_ID] = 1001
[Score] = 60
[Welcome] = 0
)

[3] = = Array
(
[LOCATION_ID] = 1003
  • 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.