降序:SELECT * FROM kc ORDER BY cpbh DESC
升序:SELECT * FROM kc ORDER BY cpbh ASC
语法:
sql可以根据字段进行排序,其中,DESC表示降序,ASC表示升序
order by 字段名 DESC;按照字段名降序排序
order by 字段名 ASC;按照字段名升序排序
实例:
一、/*查询学生表中姓名、学号,并以学号降序排序*/
select name,StuID from Students_information order by StuID desc /**order by 以什么排序,默认为升序,desc是降序*/
二、/*查询学生表中前5名学生的姓名,学号,并以学号升序排列*/
select top 5 name,StuID from Students_information order by StuID /*order by 默认为升序*/
扩展资料:
一、ORDER BY 语句
ORDER BY 语句用于根据指定的列对结果集进行排序。
ORDER BY 语句默认按照升序对记录进行排序。
如果您希望按照降序对记录进行排序,可以使用 DESC 关键字。
二、SQL 排序多个字段
order by 多个字段,每个字段后面都有排序方式,默认ASC
例如:select table a order by a.time1 ,a.time2 desc,a.time3 asc
降序
SELECT * FROM kc ORDER BY cpbh DESC
升序
SELECT * FROM kc ORDER BY cpbh asc
实例:
/*查询学生表中姓名、学号,并以学号降序排序*/
select name,StuID from Students_information order by StuID desc /**order by 以什么排序,默认为升序,desc是降序*/
/*查询学生表中前5名学生的姓名,学号,并以学号升序排列*/
select top 5 name,StuID from Students_information order by StuID /*order by 默认为升序*/
扩展资料
ORDER BY 语句:
ORDER BY 语句用于根据指定的列对结果集进行排序。
ORDER BY 语句默认按照升序对记录进行排序。
实例:
1,AddTime 升序,ID 升序
select * from DS_Finance ORDER BY AddTime,ID;
2,AddTime 升序,ID降序
select * from DS_Finance ORDER BY AddTime,ID DESC;
3,AddTime 降序,ID升序
select * from DS_Finance ORDER BY AddTime DESC,ID ;
4,AddTime 降序,ID降序
select * from DS_Finance ORDER BY AddTime DESC,ID DESC;
参考资料:百度百科-结构化查询语言
SELECT *
FROM kc
ORDER BY cpbh DESC
升序
SELECT *
FROM kc
ORDER BY cpbh asc