若sql语句中order by指定了多个字段,则怎么排序?
2022-12-11 · 百度认证:北京惠企网络技术有限公司官方账号
order by id desc,time desc
先是按 id 降序排列 (优先)
如果 id 字段 有些是一样的话 再按time 降序排列 (前提是满足id降序排列)
order by name, age desc
name优先
name一样的话,就按age排序。
后面再加第三列的话,也是一样 以此类推下去。
扩展资料:
mySql order by 几种排序的写法
1、单列升序:select<column_name> from <table_name> order by <column_name>; (默认升序,即使不写ASC)
2、单列降序:select <column_name> from <table_name> order by <column_name> desc;
3、多列升序:select <column_one>, <column_two> from <table_name> order by <column_one>, <column_two>;
4、多列降序:select <column_one>, <column_two> from <table_name> order by <column_one> desc, <column_two> desc;
5、多列混合排序:select <column_one>, <column_two> from <table_name> order by <column_one> desc, <column_two> asc;
广告 您可能关注的内容 |