排序数据查询
正常查询的数据顺序是按照插入顺序来查询的可以使用order by来设置数据的排序
语法:
select f1...... from table_name where 条件 order by f [asc/desc];
f表示按照哪列排序,asc表示升序(默认可以省略),desc表示降序,desc不能省略
a 可以按照单字段排序
--》查询表中所有的员工,同时按照工资对查询结果进行升序排列
select * from t_employee order by sal asc;
或者select * from t_employee order by sal;
--》查询表中所有的员工,同时按照工资对查询结果进行降序排列
select * from t_employee order by sal desc;
b可以按照多字段排序
--》查询表中所员工,按照工资升序,生日降序进行排列
select * from t_employee order by sal asc,Hiredate desc;
查询表中在部门10和20员工,按照工资降序查询。
select * from t_employee where deptno in(10,20) order by sal desc;