在sql中order by有N种不同的使用方法,昨天我就讲过一个order by 带等于号的做法,这里我们再介绍order by 同时排序多个字段.,ORDER BY 后可加2个字段,用英文逗号隔开.,例,代码如下:select a1,a2,a3 from t1 order by a1 desc ,a2 asc,下面看看其它实例:,f1用升序,f2降序,sql该这样写:ORDER BY f1, f2 DESC,也可以这样写,更清楚:ORDER BY f1 ASC, f2 DESC,如果都用降序,必须用两个desc:ORDER BY f1 DESC, f2 DESC,

在sql中order by有N种不同的使用方法,昨天我就讲过一个order by 带等于号的做法,这里我们再介绍order by 同时排序多个字段.

ORDER BY 后可加2个字段,用英文逗号隔开.

例,代码如下:select a1,a2,a3 from t1 order by a1 desc ,a2 asc

下面看看其它实例:

f1用升序,f2降序,sql该这样写:ORDER BY f1, f2 DESC

也可以这样写,更清楚:ORDER BY f1 ASC, f2 DESC

如果都用降序,必须用两个desc:ORDER BY f1 DESC, f2 DESC

,

在sql中order by有N种不同的使用方法,昨天我就讲过一个order by 带等于号的做法,这里我们再介绍order by 同时排序多个字段.

ORDER BY 后可加2个字段,用英文逗号隔开.

例,代码如下:select a1,a2,a3 from t1 order by a1 desc ,a2 asc

下面看看其它实例:

f1用升序,f2降序,sql该这样写:ORDER BY f1, f2 DESC

也可以这样写,更清楚:ORDER BY f1 ASC, f2 DESC

如果都用降序,必须用两个desc:ORDER BY f1 DESC, f2 DESC

最后修改:2025 年 09 月 10 日
如果觉得我的文章对你有用,请随意夸赞