




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、1. 查询工资大于12000的员工姓名和工资Select last_name|' '|first_name,salary from employees where salary >12000;2. 查询员工号为176的员工的姓名和部门号Select last_name|' '|first_name,department_id from employees where employee_id=176;3. 选择工资不在5000到12000的员工的姓名和工资Select last_name|' '|first_name,salary from
2、employees where salary not between 5000 and 12000;4. 选择雇用时间在1998-02-01到1998-05-01之间的员工姓名,job_id和雇用时间Select last_name|' '|first_name,job_id,hire_date from employees where hire_date between '1-2月-98' and '1-5月-98'5. 选择在20或50号部门工作的员工姓名和部门号Select last_name|' '|first_name,
3、department_id from employees where department_id in (20,50);6. 选择在1994年雇用的员工的姓名和雇用时间Select last_name|' '|first_name,hire_date from employees where hire_date like '%94'7. 选择公司中没有管理者的员工姓名及job_idSelect last_name|' '|first_name,job_id from employees where Manger_id is null;8. 选择公
4、司中有奖金的员工姓名,工资和奖金Select last_name|' '|first_name,salary,commission_pct from employees where commission_pct is not null;9. 选择员工姓名的第三个字母是a的员工姓名Select last_name|' '|first_name from employees where last_name|' '|first_name like '_a%'10. 选择姓名中有字母a和e的员工姓名Select last_name|
5、9; '|first_name from employees where last_name|first_name like '%a%e%' or last_name|first_name like '%e%a%' 多表查询11. 显示所有员工的姓名,部门号和部门名称。Select e.last_name,d.department_id,d.department_name from employees e , departments d where (e.department_id=d.department_id); 12. 查询90号部门员工的job_
6、id和90号部门的location_idSelect e.job_id,d.location_id from employees e, departments d where e.department_id=d.deparement_id and d.department_id=90;13. 选择所有有奖金的员工的last_name , department_name , location_id , citySelect e.last_name , d.department_name , l.location_id , city from employees e,departments d,l
7、ocations l where e.department_id=d.department_id AND d.location_id=l.location_id AND commission_pct is not null;14. 选择在Toronto工作的员工的last_name , job_id , department_id , department_name Select e.last_name , e.job_id , d.department_id , d.department_name from employees e,departments d ,locations l whe
8、re e.department_id=d.department_id AND d.location_id=l.location_id AND l.city='Toronto'15. 选择所有员工的姓名,员工号,以及他的管理者的姓名和员工号,结果类似于下面的格式employeesEmp#managerMgr#kochhar101king100Select e.employee_id "employees",e.last_name "Emp#",d.manager_id "Mgr#",d.last_name "m
9、anger" from employees e,employees d where e.manager_id=d.employee_id(+);6. 查询各部门员工姓名和他们的同事姓名,结果类似于下面的格式Department_idLast_namecolleague20fayhartsteinSelect e.department_id "Department_id", d.last_name "Last_name", e.last_name "colleague" from employees e join employ
10、ees d on(d.department_id=e.department_id) where d.last_name<>e.last_name; 分组查询16. 组函数处理多行返回一行(true)17. 组函数不计算空值( false)18. where子句在分组之前对检索进行过滤 ( true)19. 查询公司员工工资的最大值,最小值,平均值,总和Select max(salary),min(salary),avg(salary),sum(salary) from employees;20. 查询各job_id的员工工资的最大值,最小值,平均值,总和Select max(sal
11、ary),min(salary),avg(salary),sum(salary) from employees group by job_id;21. 选择具有各个job_id的员工人数Select job_id,count(*) from employees group by job_id;22. 查询员工最高工资和最低工资的差距(DIFFERENCE)Select max(salary)-min(salary) "DIFFERENCE" from employees;23. 查询各个管理者手下员工的最低工资,其中最低工资不能低于6000,没有管理者的员工不计算在内Sel
12、ect manager_id,min(salary) from employees where manager_id is not null group by manager_id having min(salary) >=6000;24. 查询所有部门的名字,location_id,员工数量和工资平均值Select d.department_name,d.location_id,count(e.employee_id),avg(e.salary) from employees e,departments d where e.department_id(+)=d.department_i
13、d group by d.location_id,d.department_name;25. 查询公司的人数,以及在1995-1998年之间,每年雇用的人数,结果类似下面的格式total1995199619971998303467Select count(employee_id),to_char(hire_date,'yyyy') "y"count(*) from employees where to_char(hire_date,'yyyy') between 1995 and 1998 group by to_char(hire_date
14、,'yyyy') order by y;Select 子查询26. 查询和zlotkey相同部门的员工姓名和雇用日期Select last_name,hire_date,department_id from employees where department_id=(select department_id from employees where lower(last_name)='zlotkey') ;27. 查询工资比公司平均工资高的员工的员工号,姓名和工资。Select employee_id,last_name,salary from employe
15、es where salary>(select avg(salary) from employees );28. 查询和姓名中包含字母u的员工在相同部门的员工的员工号和姓名Select employee_id,last_name,department_id from employees where department_id =any (select department_id from employees where lower(last_name) like '%u%');29. 查询在部门的location_id为1700的部门工作的员工的员工号,departmen
16、t_id和job_idSelect employee_id,department_id,job_id from employees where department_id = any (select department_id from departments where location_id=1700);30. 查询管理者是king的员工姓名和工资Select last_name,salary from employees where manager_id=(select employee_id from employees where last_name='King');
17、 创建和管理表31. 创建表deptnameNull?typeidNumber(7)nameVarchar2(25)Create table dept ( id Number(7),name varchar(25);32. 将表departments中的数据插入表dept中Insert into dept( SELECT department_id, department_name FROM departments);33. 创建表empnameNull?typeidNumber(7)First_nameVarchar2(25)Last_nameVarchar2(25)Dept_idNumbe
18、r(7)Create table emp (id Number(7),First_name varchar(25),Last_name varchar(25),Dept_id number(7);34. 将列Last_name的长度增加到50Alter table emp modify (last_name varchar2(50); 35. 查询数据字典视图user_tables检查刚才的操作Select * from user_tables;36. 根据表employees创建employees2Create table employees2 asselect * from employe
19、es;37. 删除表empDrop table emp;38. 将表employees2重命名为empRename employees2 to emp;39. 在表dept和emp中添加新列test_column,并检查所作的操作Alter table emp add(test_column varchar(10); 单行函数40. 显示系统时间Select to_char(sysdate 'DD-MON-YYYY')from dual;41. 查询员工号,姓名,工资,以及工资提高百分之20%后的结果(new salary)Select employee_id,last_nam
20、e|' '|first_name,salary,salary*1.2 newsalary from employees;42. 将员工的姓名按首字母排序,并写出姓名的长度(length)Select last_name,length(last_name) from employees order by substr(last_name,1,1) desc;43. 查询各员工的姓名,并显示出各员工在公司工作的月份数(worked_month)。Select last_name|" '|first_name,months_between(sysdate,hire_
21、date) worked_month from employees;44. 查询员工的姓名和工资,按下面的形式显示Last_nameSALARYking$24000Select lower(last_name) "last_name",lpad(salary,15,'$') "Salary" from employees;45. 查询员工的姓名,以及在公司工作的月份数(worked_month),并按月份数降序排列Select last_name|' '|first_name,months_between(sysdate,
22、hire_date) worked_month from employees order by worked_month desc;46. 做一个查询,产生下面的结果<last_name> earns <salary> monthly but wants <salary*3>Dream SalaryKing earns $24000 monthly but wants $72000Select 'King'|' earns '|lpad(salary,6,'$')|' monthly but wants
23、 '|lpad(salary*3,6,'$') "Dream Salary" from employees;47. 做一个查询,产生下面的结果add_month(6)+4Last_nameHire_datereiewking17-jun-87Monday,the twenty-first of December , 1987Select lower(last_name) "Last_name",hire_date,to_char(add_months(hire_date,6)+4,'DAY,MONTH,YYYY') "Hire_date " from employees where last_name like 'King'9做一个查询,产生下面的结果Employees_and_their_salarysKing*
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 家具行业劳动力资源管理试题及答案
- 2025年厦门税务个税改革惠民众改革红包我会领答题题目大全(含答案)
- 教材解析大学物理考试试题及答案
- 智能障碍测试题及答案
- 运动后功能性饮料市场推广效果评估与优化策略报告
- 会计笔试题目及答案
- 回浦中学面试真题及答案
- 黄冈社工面试真题及答案
- 学习商业对话中的语境理解试题及答案
- 有关情商测试题及答案
- 殡葬单位面试题及答案
- 民法典讲座课件
- 2025哈尔滨市木兰县辅警考试试卷真题
- 《劳动法律法规与政策》课件
- (二模)2025年广州市普通高中高三毕业班综合测试(二)生物试卷(含答案)
- 浙江省丽水市发展共同体2024-2025学年高一下学期期中联考政治试题(含答案)
- GB/T 45460-2025钢丝绳在无轴向载荷条件下钢丝绳径向刚度的测定
- 第四课第二课时《谁唱歌》课件 一年级音乐下册 湘艺版
- (四调)武汉市2025届高中毕业生四月调研考试 数学试卷(含答案详解)
- DB31T 1564-2025企业实验室危险化学品安全管理规范
- 2025版校园食堂日管控、周排查、月调度记录表
评论
0/150
提交评论