0
点赞
收藏
分享

微信扫一扫

oracle学习87-oracle之基本的过滤和排序数据之课后练习

A邱凌 2022-08-20 阅读 68

7. WHERE 子句紧随 FROM 子句

8. 查询 last_name 为 'King' 的员工信息

错误1: King 没有加上 单引号

select first_name, last_name
from employees
where last_name = King

错误2: 在单引号中的值区分大小写

select first_name, last_name
from employees
where last_name = 'king'

正确

select first_name, last_name
from employees
where last_name = 'King'

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

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

select last_name, hire_date
from employees
where hire_date = '24-4月-1998'

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

1). 使用 AND
select *
from employees
where salary >= 5000 and salary <= 10000

2). 使用 BETWEEN .. AND .., 注意: 包含边界!!
select *
from employees
where salary between 5000 and 10000

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

1). 使用 OR
select *
from employees
where salary = 6000 or salary = 7000 or salary = 8000 or salary = 9000 or salary = 10000

2). 使用 IN
select *
from employees
where salary in (6000, 7000, 8000, 9000, 10000)

12. 查询 LAST_NAME 中有 'o' 字符的所有员工信息.

select *
from employees
where last_name like '%o%'

13. 查询 LAST_NAME 中第二个字符是 'o' 的所有员工信息.

select *
from employees
where last_name like '_o%'

14. 查询 LAST_NAME 中含有 '_' 字符的所有员工信息

1). 准备工作:
update employees
set last_name = 'Jones_Tom'
where employee_id = 195

2). 使用 escape 说明转义字符.
select *
from employees
where last_name like '%\_%' escape '\'

15. 查询 COMMISSION_PCT 字段为空的所有员工信息
select last_name, commission_pct
from employees
where commission_pct is null

16. 查询 COMMISSION_PCT 字段不为空的所有员工信息
select last_name, commission_pct
from employees
where commission_pct is not null

17. ORDER BY:
1). 若查询中有表达式运算, 一般使用别名排序
2). 按多个列排序: 先按第一列排序, 若第一列中有相同的, 再按第二列排序.
格式: ORDER BY 一级排序列 ASC/DESC,二级排序列 ASC/DESC;



举报

相关推荐

0 条评论