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

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;

posted @   前端导师歌谣  阅读(17)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
点击右上角即可分享
微信分享提示