mysql排序order by

文章目录


一、介绍

  • 位置:where的后面;limit的前面
sql 复制代码
-- 单字段
order by 字段名/查询字段的位置 排序规则(asc升序-默认,可省略/desc降序);

-- 多字段
order by 字段名1 asc/desc,字段名2 asc/desc;

二、例子

sql 复制代码
-- 单字段升序
select
    name,create_time
from t_user
order by create_time;

-- 多字段升序、降序
-- 如果部门id一样,则按照工资降序
select
    dept_name,sal
from t_user
order by dept_id,sal desc;
相关推荐
Full Stack Developme27 分钟前
Java 日期时间处理:分类、用途与性能分析
java·开发语言·数据库
雪碧聊技术2 小时前
存储过程的介绍、基本语法、delimiter的使用
数据库·存储过程的基本语法·delimiter的使用
_码农121383 小时前
spring boot 使用mybatis简单连接数据库+连表查询
数据库·spring boot·mybatis
掘根5 小时前
【MySQL集群架构与实践5】使用Docker实现水平分片
mysql·docker·架构
TTBIGDATA6 小时前
【支持Ubuntu22】Ambari3.0.0+Bigtop3.2.0——Step7—Mariadb初始化
数据库·ambari·hdp·mariadb·bigtop·ttbigdata·hidataplus
大得3696 小时前
django的数据库原生操作sql
数据库·sql·django
tuokuac6 小时前
SQL中的HAVING用法
数据库·sql
爬山算法6 小时前
MySQL(173)MySQL中的存储过程和函数有什么区别?
数据库·mysql
jnrjian6 小时前
利用trigger对大表在线同步 UDI
数据库·sql
Ruimin05196 小时前
Mysql集群技术
数据库·mysql