



全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
SQL练习题表1 Employee表编号姓名地址邮编电话电子邮件部门出生日期性别NumNameAddrZipTelEmailDepnoBirthSex001王林武汉大学43007487598405Null21985-2-1男002王芳华中科大43007362534231Null11966-3-28男003张晓武汉理工大43007287596985Null11972-12-9男004王小燕武汉交大4300718574326111950-7-30女005李华华中农大43007087569865Null51962-10-18男006李明华中师大4300758536214351955-09-28男007田丽中南财大4300768569326531968-08-10女008吴天武汉电力4300773698561251964-10-01男009刘备武汉邮科院43007869865231Null31967-04-02男010张飞武汉软通4300796986563241958-09-20男011赵云学府家园43007168592312Null41968-11-18男012貂禅湖北工大43007465987654null41959-09-03女表2 Department编号部门名称备注DepnoDepNameRemark1财务部Null2人力资源部Null3经理办公室Null4研发部Null5市场部Null表3 salary编号收入支出NumInComeOutCome0012100.8123.090021582.6288.030032569.88185.650041987.0179.580052066.15108.00062980.7210.20073259.98281.520082860.01980092347.681800102531.98199.080112240.0121.00121980.0100.0练习1:SELECT语句的基本使用(1) 查询每个雇员的所有记录; select *from employee(2) 查询前5个会员的所有记录; select *from employee where num between 001 and 005Select top 5 * from employee(3) 查询每个雇员的地址和电话;select num,addr,tel from employee(4) 查询num为001的雇员地址和电话; select num,addr,tel from employee where num=001(5) 查询表Employee表中女雇员的地址和电话,使用AS子句将结果列中各列的标题分别指定为地址、电话; select num 雇员号,addr 地址,tel 电话 from employee where sex=女 说明:oracle重新定义别名不是用as,而是空格(6) 计算每个雇员的实际收入; select num,income-outcome come from salary(7) 找出所有姓王的雇员的部门号(部门号不能重复显示); select distinct depno from employee where name like 王%(8) 找出所有收入在20003000元之间的雇员编号 select num from salary where income between 2000 and 3000练习2:子查询的使用(答案可以不唯一)(1) 查找在财务部工作的雇员情况;select * from employee where depno=(select depno from department where depname=财务部)也可用 inselect * from employee where depno in (select depno from department where depname=财务部)也可用 exists (所有的IN均可用Exists表示)select * from employee where exists (select * from department where employee.depno=department.depno and depname=财务部)exists 的特点:(2) 查找在财务部且年龄不低于研发部任一个雇员年龄的雇员的姓名; select name from employee where depno=(select depno from department where depname=财务部) and birth=(select min(birth) from employee where depno=(select depno from department where depname=研发部) (注意:年龄越大,生日越小)也可用select name from employee where depno=(select depno from department where depname=财务部) and birth(select max(income) from salary where num in(select num from employee where depno=(select depno from department where depname=财务部) ) 练习3:连接查询的使用(1) 查找每个雇员的情况及薪水情况;select employee.*,income,outcome from employee,salary where employee.num=salary.num(2) 查找财务部收入在2200元以上的雇员姓名及其薪水详细情况; Select name,income,outcome from employee,department,salary where employee.num=salary.num and employee.depno=department.depno and depname=财务部 and income2200练习4:数据汇总(1) 求财务部雇员的平均实际收入; select avg(income-outcome) avg_come from salary where num in(select num from employee where depno=(select depno from department where depname=财务部 )也可改成连结查询select avg(income-outcome) avg_come from salary,employee,department where salary.num=employee.num and employee.departnum=department.departnum and department.depname=财务部 (2) 求财务部雇员的总人数; select count(*) 财务部人数 from employee where depno=(select depno from department where depname=财务部 )思考问题:如何改成连接查询练习5:GROUP BY 、ORDER BY 子句的使用(1) 求各部门的雇员数(要求显示,部门号、部门名称和部门雇员数); select department.depno,depname,count(employee.depno) from employee,department where department.depno *= employee.depno group by department.depno,depname注意:统计列的要求思考问题,上题如改成按雇员数量降序排列,如何实现?增加Order by count(employee.depno) DESC (2) 求部门的平均薪水大于2500的部门信息(要求显示,部门号、部门名称和平均工资) select departmen
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 离婚协议书范本针对离婚后子女医疗问题的协议
- 婚姻解除协议书范本:共同子女抚养及监护权分配
- 金融控股公司债权债务三方转让与集团化运营协议
- 创意离婚协议书:财产分割与子女抚养权纠纷处理方案
- 精准对接个人对个人直升机租赁及观光服务协议
- 物流行业生产经营信息保密与物流服务质量协议
- 离婚协议书范本:子女教育及监护问题
- 公共停车场物业经营权及收益分成合作协议
- 班组级安全培训内容课件
- 《公共关系原理与实务》 第四版 练习与答案 朱崇娴 第6-11章
- SB/T 11112-2015电子商务企业认定规范
- 正高级会计师答辩面试资料
- 《计算机网络(第5版)》英文版教学课件
- 幼儿园事故案例分析及法律法规课件-幼儿园事故案例及分析
- 长坂坡隧道照明施工方案
- 修理厂焊工安全生产责任清单
- 输液泵/微量注射泵使用技术操作考核评分标准
- 气流粉碎机课件
- 梁若瑜著-十二宫六七二象书增注版
- 环境影响评价报告公示:兴丰填埋场沼气发电利用项目环评报告
- SJG 74-2020 深圳市安装工程消耗量定额-高清现行
评论
0/150
提交评论