Mysql 这样可以一句sql出来吗-- phpMyAdmin SQL Dump-- version 2.10.2-- http://www.phpmyadmin.net---- 主机: localhost-- 生成日期: 2013 年 01 月 25 日 06:32-- 服务器版本: 5.0.45-- PHP 版本: 5.2.3 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";---- 数据库: `test`---- ------------------------ 表的结构 `location`--CREATE TABLE `location` (`location_id` int(10) unsigned NOT NULL,`score` int(10) unsigned NOT NULL,`welcome` tinyint(3) unsigned NOT NULL,PRIMARY KEY (`location_id`)) ENGINE=MyISAM DEFAULT CHARSET=gbk;---- 导出表中的数据 `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);
排序要求:
如果 welcome 为1 则按score + 50 来排例查询两条数据 按 score DESC结果为location_id为1000和1002的两条数据求助 感谢 !
mysql------解决方案--------------------引用:引用:表述的不清楚!是不是要把 welcome 为1 的排在前面?select * from location order by welcome=1 desc, score DESC版主 是这样的 我想将 welcome=1的 score + 50,再按score倒序来排。前提是不改变原表的值。
这样写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
