OracleSQL讲义(Student)(3)

2019-05-18 11:18

--- 连接运算 ||

例子4:显示所有员工的全名? Select last_name,first_name from s_emp 例子5:显示所有地区的内容?

Select * from s_region;

--- 算术表达式(Arithmetic Expressions) 例子6:列出每个员工的年薪?

--- NULL值:算术表达式包含空值,则结果为空 --- NVL 用法:用来把一个NULL值转换成实际的值 Nvl(commission_pct,0) 让null变成实际的值

例子7:列出每个员工的总工资?

--- distinct的工作模式:从distinct之后到from之前全部唯一

例子8:列出各部门有什么不同的职位? Select distinct dept_id,title from s_emp

选择操作和投影操作已经完成。 十、 限定查询:

--- SELECT [DISTINCT] FROM table_name;

WHERE [Column name], [expression], [constant],

[Comparison operator]

{*, column [alias], ...}

[Literal]

例子9: 找出工资高于1500元的员工?

select id,first_name,salary from s_emp where salary > 1500;

例子10: 找出工资高于1500元的员工的年薪?

select id,first_name,salary*12 from s_emp where salary >=1500;

例子11: 找出年薪高于12000元的员工?

select id,first_name,salary*12 from s_emp where salary*12 >12000;

例子12: 找出42部门年薪高于12000元的员工? select dept_id,first_name,salary*12 from s_emp where salary*12 >12000 and dept_id = 42; 总结:

1、where尽量不使用表达式; 2、where中不能使用别名;

例子13: 找出‘Carmen’每个月的工资? select id,first_name,salary from s_emp where first_name='Carmen'或like

例子14: 把所有职位为stack clerk的员工列出? --- 逻辑比较运算符 >= = <=

--- SQL比较运算符

--- between and : 包括边界值

例子15: 找出工资在1500-2000之间的员工? Select id,first_name,salary From s_emp

Where salary >= 1500 and salary <= 2000

或where between 1500 and 2000

--- 逻辑运算符(Logical operators) and、or、not、 in、any

例子16: 找出31, 42, 43 部门的员工的工资? select id,first_name,salary from s_emp

where dept_id = 31 or dept_id = 42 or dept_id = 43

或where dept_id = any(31,42,43) 或where dept_id in (31,42,43) 如果不在的话用not in(31,42,43) 或 <>all(31,42,43) --- Like '%' '_'

例子17:找出first_name第二个字母是 e 的员工信息? select

id,first_name,salary

from

s_emp

where

first_name like '_e%';

--- 转义符 escape的使用

例子18:列出当前用户下所有以‘S_’开头的表?(escape) Escape ‘#’ ‘#’后面被转译

select table_name from tabs

where table_name like 'S#_%' escape '#'

例子19:找出入职时间是 90年的所有员工信息?

select id,first_name,start_date from s_emp

where start_date like '?'

--- 否定表达式(Negating Expressions) Logical Operators

!= <> ^= SQL Operators NOT BETWEEN NOT IN NOT LIKE IS NOT NULL

例子20:列出哪些员工没有提成?

select id,first_name,salary from s_emp where commission_pct is null

例子21:列出不在31, 42, 43 部门的员工的工资?

Select id,first_name,salary from s_emp Where dept_id not in(31,43,43)

或where dept_id ^=31 and dept_id!=43 and dept_id <>42

例子22:列出 42, 43 部门工资大于1000元的员工信息?

select id,first_name,dept_id,salary from s_emp where dept_id in(42,43) and salary > 1000 或where salary > 1000 and (dept_id =42 or Dept_id =43) 十一、

The ORDER BY Clause:(排序)

--- ASC – 升序ascending order, (default). DESC 降序– descending order.

ORDER BY clause is last in SELECT command. 例子23: 按工资降序显示员工的信息? Select id,first_name,salary from s_emp Order by salary desc 降序 一般默认是升序

例子24: 按提成升序显示员工的信息? Select id,first_name,salary from s_emp Order by commission_pct asc

注意:null(排序做无穷大处理)


OracleSQL讲义(Student)(3).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:地基与基础试题库(含答案)

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: