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