SQL学习之排序与过滤

xiaoxiao2021-02-28  155

过滤

其中salary表示工资 条件过滤需要where

select name,age,salary from pesion where salary>5000

工资在5000至8000之间查询两种方法,建议用第二种

select name, salary from pesion where salary>5000 and salary<=8000 select name,salary from pesion where between 4000 and 8000

–查询时间段 举例: 查询雇用时间在1998年2月1日到1998年5月20日之间员工的姓名工号和时间 姓名:job_name 工号:job_id 雇用时间:hire_date

select job_name,job_id,hire_date from Pesion where to_char(hire_date,'yyyy-mm-dd') between '1998-02-01' and '1998-05-20'

模糊查询 –like 举例: 一个公司中员工名字含有a的员工有那些

select name from pesion where name like'%a%' //其中%代表a前面的字符串和a后面的字符串

–名字中第二位字符是a 员工

select name from pesion where name like '_a%' //一个"_"代表一个字符

排序

select name,salary from pesion order by salary desc //desc升序排序(由大到小) select name,salary from pesion order by salary asc //asc降序排序(由小到大) select name,salary from pesion order by salary //不写desc或者asc 默认从小到大排序

–多层排序

select name,salary from pesion order by salary asc,name asc

–别名排序

select name,salary,12*salary annual_sal from pesion order by annual_sal
转载请注明原文地址: https://www.6miu.com/read-36769.html

最新回复(0)