第二章 过滤和排序数据总结与测试

第二章 过滤和排序数据
总结:

1.where子句紧随FROM子句

2.查询last_name为’King’的员工信息

select first_name,last_name
 	from employees
	where last_name=king
 --king没有加上单引号
select first_name,last_name
	from employees
	where last_name='king'
--在单引号号中的值区分大小写
select first_name,last_name
	from employees
	where last_name='King'
--正确

3.查询1998-4-24来公司的员工有哪些?

注意:日期必须要放在单引号中,且必须是指定的格式

select last_name,hire_date 
	from employees
	where hire_date ='24-4月-1998'
	--where to_char(hire_date,'yyyy-mm-dd')='1998-04-24'

4.查询工资在5000-10000之间员工的信息。

--1.使用and
select * 
	from employees
	where salary>=5000 and salary<10000;
--2.between...and
select *
	from employees
	where 5000 and 10000;

5.查询工资等于6000,7000,9000,10000的员工信息。

--使用or
 select * 
  	from employees 
  	where salary=6000 or salary=7000 or salary=9000 or salary=10000;
--使用in
select *
	from employees
	where salary in (6000,7000,9000,10000);
  1. 查询LAST_NAME中有’o’的所有员工信息。
  select *
  	from employees
   	where LAST_NAME like '%o%';
  1. 查询LAST_NAME中第二个字符是’o’的所有员工信息。
  select *
  	from employees
  	where LAST_NAME like '_o%';
  1. 查询LAST_NAME中含有’_'的所有员工信息。
  --准备工作
  update employees
  	set LAST_NAME='Jones_Tom'
  	where employees_id=195;
  --使用escape说明转义字符
  select *
  	from employees
  	where LAST_NAME like '\_' escape '\';
  1. 查询COMMISSION_PCT字段为空的所有员工信息
 select last_name,commission_pct
 	from employees
 	where commission_pct is  null;

10.查询COMMISSION_PCT字段不为空的所有员工信息

select last_name,
	from employees
	where commission_pct is not null;
  1. order by:

    (1).若查询中表达式运算,一般使用别名排序

    (2).按多个列排序:先按第一列排序,若第一列中有相同的,再按第二列。

    格式: ORDER BY 一般排序列ASC/DESC,二级排序列ASC/DESC

测试:

1.查询工资大于12000的员工姓名和工资。

select last_name ,salary
	from employees 
	where salary > 12000;

2.查询员工号位为176的员工的姓名和部门号。

select last_name , department_id
	from employees 
	where employee_id=176;

3.选择工资不在5000到12000的员工的姓名和工资

select last_name ,salary 
	from employees
	--where salary <5000 and salary 12000;
	where salary not between 5000 and 12000;

4.选择聘用事件在1998-02-01到1998-05-01之间员工姓名,job_id和聘用时间

select last_name,job_id,hire_date
	from employees
	-- where hire_date between '1-2月-1998' and '1-5月-1998';
	where to_char(hire_date,'yyyy-mm-dd') between '1998-02-01' and '1998-05-01';

5.选择在20或50号部门工作的员工姓名和部门号

select last_name, department_id
	from employees
	--where department_id = 20 or department_id = 50;
	where department_id in (20,50) ;

6.选择在1994年聘用的员工的姓名和聘用时间

select last_name,hire_date
	from employees
	--where hire_date like '%94'
	where tochar(hire_date,'yyyy') ='1994';

7.选择公司中没有管理者的员工姓名及job_id

select last_name,job_id
	from employees
	where manager_id is null;

8.选择公司中有奖金的员工姓名,工资和奖金级别

select last_name,salary,commission_pct
	from employees
	where commission_pct is not null;

9.选择员工姓名的第三个字母是a的员工姓名

select last_name 
	from employees
	where last_name like '__a%';

10.选择姓名中有字母a和e的员工姓名

select last_name
form employees
where last_name like '%a%e%' or last_name like '%e%a%';
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值