ImageVerifierCode 换一换
格式:DOCX , 页数:10 ,大小:173.38KB ,
资源ID:4263382      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/4263382.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(李贺数据库4.docx)为本站会员(b****4)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

李贺数据库4.docx

1、李贺数据库4云南大学软件学院 实验报告课程: 数据库原理与实用技术实验 学期: 2012-2013学年 第二学期 任课教师: 薛岗 专业:软件工程 学号: 20111120038 姓名: 李贺 成绩: 实验4 数据查询一、实验目的(1)理解T-SQL语言的使用。(2)熟练掌握数据查询语句。(3)掌握合计函数的使用。二、实验内容1、CAP数据库的查询(记录每个查询的SQL语句和查询结果)(1)建立CAP数据库,输入C、A、P、O四张表;(2)完成课后习题3.2b、3.5、3.8a,b、3.11b,f,j,l 3.2 (b) Retrieve aid values of agents who re

2、ceive the maximum percent commission.Answer:The aid values of agents who receive the maximum percent commission is a03. select aid from AGENTS where percents = any (select max(percents) from AGENTS)3.5 Consider the problem to find all (cid, aid) pairs where the customer does not place an order throu

3、gh the agent. This can be accomplished with the Select statementselect cid, aid from customers c agents a where not exists (select * from orders x where x.cid = c.cid and x.aid =a.aid) ;Is it possible to achieve this result using the NOT IN predicate in place of the NOT EXISTS predicate with a singl

4、e Subquery? With more than one Subquery? Explain your answer and demonstrate any equivalent form by execution.(1) select cid,aid from CUSTOMERS,AGENTS where (cid not in (select cid from ORDERS where ORDERS.aid=AGENTS.aid)select cid,aid from CUSTOMERS,AGENTS where (aid not in (select aid from ORDERS

5、where ORDERS.cid=CUSTOMERS.cid) (2)select cid,aid from CUSTOMERS,AGENTS where (cid not in (select cid from ORDERS where cid in (select cid from ORDERS where ORDERS.aid=AGENTS.aid)3.8 (a) Write a Select statement with no WHERE clause to retrieve all customer cids and the maximum money each spends on

6、any product. Label the columns of the resulting table: eid, MAXSPENT. SELECT cid,max(dollars) as MAXSPENT from orders group by cid (b) Write a query to retrieve the AVERAGE value (over all customers) of the MAXSPENT of query (a) SELECT cid,max(dollars) as MAXSPENT INTO #OrderPay from orders group by

7、 cid SELECT avg(MAXSPENT) as average from #OrderPay3.11 (b) We say that a customer x orders a product y in an average quantity A if A is avg(qty) for all orders rows with cid = x and pid = y. Is it possible in a single SQL statement to retrieve cid values of customers who order all the products that

8、 they receive in average quantities (by product) of at least 300?select distinct cid from orders group by cid,pid having avg(qty)=300(f) Get pid values of products that are ordered by all customers in Dallas. select p.pid from products p where not exists (select * from customers c where c.city=Dalla

9、s and not exists (select * from orders x where x.cid=c.cid and x.pid=p.pid)(j) Use a single Update statement to raise the prices of all products warehoused in Duluth or Dallas by 10%. Then restore the original values by rerunning the procedure that you originally used to create and load the products

10、 table.UPDATE PRODUCTS SET price=price*1.1 where city=Duluth or city=Dallas(l) Write an SQL query to get aid and percent values of agents who take orders from all customers who live in Duluth. The aid values should be reported in order by decreasing percent. (Note that if percent is not retriuse CAP

11、GOselect aid,percents from agents awhere not exists (select * from customers cwhere c.city=Duluth and not exists (select * from orders xwhere x.cid=c.cid and x.aid=a.aid)order by a.percents2、Employee数据库的查询(记录每个查询的SQL语句和查询结果)(1)向表中插入数据。(2)将职工编号为000006的员工3月份基本工资增加为3000,奖金增加到800。Update salarySet base=3

12、000 , Bonus=800where Pno=000006 and Month=3(3)员工000009已经离开公司,将该员工的数据删除 DELETE FROM person WHERE Pno = 000009 DELETE FROM salary WHERE Pno = 000009(4)简单条件查询 查询person表中所有不重复的职称。SELECT DISTINCT Prof FROM person 查询具有高级职称的女员工信息SELECT * FROM person p where p.Prof=高级 and p.Sex=女 查询职工姓名为黎明的员工数据SELECT * FROM

13、 person p where p.Pname=黎明 查询各部门的实发工资总数SELECT Deptno,SUM(Fact) as total from salary,department WHERE pno in (SELECT pno from person where department.deptno=person.deptno) group by deptno(5)复杂条件查询 查询平均工资高于3000的部门名和对应的平均工资。 select deptno,avg(Fact) as average INTO #AVESALARY from department,salary wher

14、e pno in(select pno from person where department.deptno=person.deptno)group by deptno select dname,average from department,#AVESALARY where average3000 and department.deptno=#AVESALARY.deptno 查询1月份实发工资比平均实发工资高的员工姓名和实发工资额。 SELECT pname,Fact from person,salary where Fact=ALL (SELECT average from #AVES

15、ALARY where #AVESALARY.Deptno=person.Deptno) and month=1and person.pno=salary.pno 查询2月份实发工资比一月高的员工姓名。 select pname from person,salary x where month=2 and Fact(select Fact from salary y where x.pno=y.pno and month=1) and person.pno=x.pno 利用sql语句将1,2,3月累积的员工的实发工资按降序排序 select pno,sum(Fact) as ssalary INTO sumsalary from salary group by pno order by ssalary DESC

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1