云南大学软件学院数据库实验4.docx

上传人:b****3 文档编号:6062153 上传时间:2023-05-09 格式:DOCX 页数:14 大小:271.76KB
下载 相关 举报
云南大学软件学院数据库实验4.docx_第1页
第1页 / 共14页
云南大学软件学院数据库实验4.docx_第2页
第2页 / 共14页
云南大学软件学院数据库实验4.docx_第3页
第3页 / 共14页
云南大学软件学院数据库实验4.docx_第4页
第4页 / 共14页
云南大学软件学院数据库实验4.docx_第5页
第5页 / 共14页
云南大学软件学院数据库实验4.docx_第6页
第6页 / 共14页
云南大学软件学院数据库实验4.docx_第7页
第7页 / 共14页
云南大学软件学院数据库实验4.docx_第8页
第8页 / 共14页
云南大学软件学院数据库实验4.docx_第9页
第9页 / 共14页
云南大学软件学院数据库实验4.docx_第10页
第10页 / 共14页
云南大学软件学院数据库实验4.docx_第11页
第11页 / 共14页
云南大学软件学院数据库实验4.docx_第12页
第12页 / 共14页
云南大学软件学院数据库实验4.docx_第13页
第13页 / 共14页
云南大学软件学院数据库实验4.docx_第14页
第14页 / 共14页
亲,该文档总共14页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

云南大学软件学院数据库实验4.docx

《云南大学软件学院数据库实验4.docx》由会员分享,可在线阅读,更多相关《云南大学软件学院数据库实验4.docx(14页珍藏版)》请在冰点文库上搜索。

云南大学软件学院数据库实验4.docx

云南大学软件学院数据库实验4

云南大学软件学院实验报告

课程:

数据库原理与实用技术实验学期:

2012-2013学年第二学期任课教师:

专业:

学号:

姓名:

成绩:

实验4数据查询

一、实验目的

理解T-SQL语言的使用;熟练掌握数据查询语句;掌握合计函数的使用。

二、实验内容

1、CAP数据库的查询(记录每个查询的SQL语句和查询结果)

(1)建立CAP数据库,输入C、A、P、O四张表;

图表1创建cap数据库

图表2创建四个表

图表3向表中插入数据

图表4表的内容

(2)完成课后习题[3.2]b、[3.5]、[3.8]a,b、[3.11]b,f,j,l

[3.2](b)Retrieveaidvaluesofagentswhoreceivethemaximumpercentcommission.

图表5最高佣金百分率

[3.5]Considertheproblemtofindall(cid,aid)pairswherethecustomerdoesnotplaceanorderthroughtheagent.ThiscanbeaccomplishedwiththeSelectstatement

selectcid,aid

fromcustomersc.agentsa

wherenotexists

(select*fromordersxwherex.cid=c.cidandx.aid=a.aid);

IsitpossibletoachievethisresultusingtheNOTINpredicateinplaceoftheNOTEXISTSpredicatewithasingleSubquery?

WithmorethanoneSubquery?

Explainyouransweranddemonstrateanyequivalentformbyexecution.

图表63.5notin

[3.8](a)WriteaSelectstatementwithnoWHEREclausetoretrieveallcustomercidsandthemaximummoneyeachspendsonanyproduct.Labelthecolumnsoftheresultingtable:

eid,MAXSPENT.

图表73.8

(b)WriteaquerytoretrievetheAVERAGEvalue(overallcustomers)oftheMAXSPENTofquery(a)

图表83.8(b)

[3.11](b)WesaythatacustomerxordersaproductyinanaveragequantityAifAisavg(qty)forallordersrowswithcid=xandpid=y.IsitpossibleinasingleSQLstatementtoretrievecidvaluesofcustomerswhoorderalltheproductsthattheyreceiveinaveragequantities(byproduct)ofatleast300?

图表93.11(b)

(f)GetpidvaluesofproductsthatareorderedbyallcustomersinDallas.

图表103.11(f)

(j)UseasingleUpdatestatementtoraisethepricesofallproductswarehousedinDuluthorDallasby10%.Thenrestoretheoriginalvaluesbyrerunningtheprocedurethatyouoriginallyusedtocreateandloadtheproductstable.

图表113.11(j)

(l)WriteanSQLquerytogetaidandpercentvaluesofagentswhotakeordersfromallcustomerswholiveinDuluth.Theaidvaluesshouldbereportedinorderbydecreasingpercent.(Notethatifpercentisnotretrievedintheselectlist,wecannotorderbythesevalues.)

图表123.11(i)

2、Employee数据库的查询(记录每个查询的SQL语句和查询结果)

(1)向表中插入数据。

useEmployee1

INSERTINTOdepartmentvalues('001','营销部');

INSERTINTOdepartmentvalues('002','财务部');

INSERTINTOdepartmentvalues('003','人事部');

INSERTINTOdepartmentvalues('004','采购部');

select*fromdepartment

INSERTINTOpersonvalues('000001','田林','男','1982/4/7','初级','001');

INSERTINTOpersonvalues('000002','郭达','男','1953/2/14','高级','001');

INSERTINTOpersonvalues('000003','王林','女','1984/8/25','初级','002');

INSERTINTOpersonvalues('000004','王辉','男','1984/5/11','初级','002');

INSERTINTOpersonvalues('000005','罗大右','男','1968/12/10','高级','002');

INSERTINTOpersonvalues('000006','蔡琴','女','1978/4/20','中级','003');

INSERTINTOpersonvalues('000007','李艳','女','1960/5/14','高级','001');

INSERTINTOpersonvalues('000008','刘德华','男','1971/2/19','高级','003');

INSERTINTOpersonvalues('000009','黎明','男','1973/10/9','中级','002');

select*fromperson

INSERTINTOsalaryvalues('000001',2100,500,1);

INSERTINTOsalaryvalues('000002',3000,600,1);

INSERTINTOsalaryvalues('000003',2800,450,1);

INSERTINTOsalaryvalues('000004',2500,340,1);

INSERTINTOsalaryvalues('000005',3200,490,1);

INSERTINTOsalaryvalues('000006',2700,600,1);

INSERTINTOsalaryvalues('000007',4000,200,1);

INSERTINTOsalaryvalues('000008',2800,350,1);

INSERTINTOsalaryvalues('000009',2760,440,1);

INSERTINTOsalaryvalues('000001',2400,600,2);

INSERTINTOsalaryvalues('000002',2800,400,2);

INSERTINTOsalaryvalues('000003',2860,350,2);

INSERTINTOsalaryvalues('000004',2540,320,2);

INSERTINTOsalaryvalues('000005',3200,480,2);

INSERTINTOsalaryvalues('000006',2700,300,2);

INSERTINTOsalaryvalues('000007',4000,250,2);

INSERTINTOsalaryvalues('000008',2800,300,2);

INSERTINTOsalaryvalues('000009',2760,480,2);

INSERTINTOsalaryvalues('000001',2200,500,3);

INSERTINTOsalaryvalues('000002',3100,400,3);

INSERTINTOsalaryvalues('000003',2800,650,3);

INSERTINTOsalaryvalues('000004',2500,540,3);

INSERTINTOsalaryvalues('000005',3200,400,3);

INSERTINTOsalaryvalues('000006',2700,660,3);

INSERTINTOsalaryvalues('000007',4100,400,3);

INSERTINTOsalaryvalues('000008',2000,330,3);

INSERTINTOsalaryvalues('000009',2760,420,3);

select*fromsalary

图表13表的内容

图表14修改Fact的值

(2)将职工编号为000006的员工3月份基本工资增加为3000,奖金增加到800。

图表15更新表的内容

(3)员工000009已经离开公司,将该员工的数据删除

图表16删除表中数据

(4)简单条件查询

✓查询person表中所有不重复的职称。

图表17查询不重复的职称

✓查询具有高级职称的女员工信息

图表18查询内容

✓查询职工姓名为黎明的员工数据

图表19查询表的内容

✓查询各部门的实发工资总数

(5)复杂条件查询

✓查询平均工资高于3000的部门名和对应的平均工资。

图表20表的统计

✓查询1月份实发工资比平均实发工资高的员工姓名和实发工资额。

图表21查询表的内容

✓查询2月份实发工资比一月高的员工姓名。

图表22查询表的内容

✓利用sql语句将1,2,3月累积的员工的实发工资按降序排序

图表23工资降序排列

(注:

可编辑下载,若有不当之处,请指正,谢谢!

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 自然科学 > 物理

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2