MySQL ORDER BY 排序
2018-10-19 本文已影响0人
soeben
语法
SELECT * FROM table ORDER BY field1 [ASC|DESC], field2 [ASC|DESC];
ASC升序 DESC降序
例子
//结构
CREATE TABLE `user` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` varchar(10) NOT NULL,
`sex` tinyint(4) NOT NULL,
`tel` char(11) NOT NULL,
PRIMARY KEY (`id`)
)ENGINE=InnoDB DEFAULT CHARACTER SET utf8;
//单个字段排序
SELECT * FROM `user` ORDER BY `id` ASC;
//多个字段排序
SELECT * FROM `user` ORDER BY `id` ASC, `tel` DESC;