order by的升序和降序
时间: 2024-04-18 18:20:07 浏览: 200
SQL-ORDER BY 多字段排序(升序、降序)
5星 · 资源好评率100%
order by语句用于对查询结果进行排序。在SQL语句中,asc表示按升序排列,desc表示按降序排列。以下是一些示例:
1. 单列升序排列:
```sql
select * from tablename order by c2 asc;
```
2. 单列降序排列:
```sql
select * from tablename order by c2 desc;
```
3. 多列复合排序,先按第一列升序排列,再按第二列降序排列:
```sql
select * from tablename order by c1 asc, c2 desc;
```
4. 示例引用中的排序示例:
```sql
-- AddTime升序,ID升序
select * from DS_Finance ORDER BY AddTime,ID;
-- AddTime升序,ID降序
select * from DS_Finance ORDER BY AddTime,ID DESC;
-- AddTime降序,ID升序
select * from DS_Finance ORDER BY AddTime DESC,ID;
-- AddTime降序,ID降序
select * from DS_Finance ORDER BY AddTime DESC,ID DESC;
```
阅读全文