美文网首页
MySQL ORDER BY 排序

MySQL ORDER BY 排序

作者: soeben | 来源:发表于2018-10-19 16:04 被阅读0次

    语法

    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;
    

    相关文章

      网友评论

          本文标题:MySQL ORDER BY 排序

          本文链接:https://www.haomeiwen.com/subject/ietuzftx.html