练习1

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

第一天练习

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 not between5000and12000

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'

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

select last_name, department_id

from employees

where department_id in (20, 50)

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

select last_name, hire_date

from employees

where hire_date like'% -94'

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

from employees

where last_name like'%a%'and last_name like'%e%'

11.显示系统时间

select to_char(sysdate, 'yyyy-mm-dd hh:mi:ss') from dual;

12.查询员工号,姓名,工资,以及工资提高百分之20%后的结果(new

salary)

select employee_id, last_name, salary, salary * 1.2"new salary"

from employees;

13.将员工的姓名按首字母排序,并写出姓名的长度(length)

select last_name, length(last_name)

from employees

order by last_name

14.查询各员工的姓名,并显示出各员工在公司工作的月份数

(worked_month)。

select last_name, months_between(sysdate, hire_date) worked_month from employees

15.查询员工的姓名,以及在公司工作的月份数(worked_month),

并按月份数降序排列

select last_name, months_between(sysdate, hire_date) worked_month from employees

order by worked_month desc

16.做一个查询,产生下面的结果

earns monthly but wants

17.使用decode函数,按照下面的条件:

job grade

AD_PRES A

ST_MAN B

IT_PROG C

SA_REP D

ST_CLERK E

Others F

产生下面的结果

18.将第7题的查询用case函数再写一遍。

select last_name, job_id, case job_id when'AD_PRES'then'A'

when'ST_MAN'then'B'

when'IT_PROG'then'C'

when'SA_REP'then'D'

when'ST_CLERK'then'E'

else'F'

end

from employees

19.查询公司员工工资的最大值,最小值,平均值,总和

Select max(salary), min(salary), avg(salary), sum(salary)

From employees

20.查询各job_id的员工工资的最大值,最小值,平均值,总和Select job_id, max(salary), min(salary), avg(salary), sum(salary)

From employees

Group by job_id

21.选择具有各个job_id的员工人数

Select job_id, count(employee_id)

From employees

Group by job_id;

22.查询员工最高工资和最低工资的差距(DIFFERENCE)

Select max(salary) – min(salary) difference

From employees

23.查询各个管理者手下员工的最低工资,其中最低工资不能低于

6000,没有管理者的员工不计算在内

Select manager_id, min(salary)

From employees

Where manager_id is not null

Group by manager_id

Having min(salary) >= 6000

相关文档
最新文档