数据库实验报告

上传人:m**** 文档编号:559992531 上传时间:2024-02-06 格式:DOCX 页数:12 大小:78.69KB
返回 下载 相关 举报
数据库实验报告_第1页
第1页 / 共12页
数据库实验报告_第2页
第2页 / 共12页
数据库实验报告_第3页
第3页 / 共12页
数据库实验报告_第4页
第4页 / 共12页
数据库实验报告_第5页
第5页 / 共12页
点击查看更多>>
资源描述

《数据库实验报告》由会员分享,可在线阅读,更多相关《数据库实验报告(12页珍藏版)》请在金锄头文库上搜索。

1、沈阳工程学院学生实验报告(课程名称:数据库系统原理)实验题目:数据查询(二)班级学号姓名日期 年月曰 地点指导教师一、实验目的掌握SQL查询命令:包括连接查询、嵌套查询和集合查询。二、实验环境OraclelOg数据库系统。三、实验内容与要求使用Select命令完成下列数据查询。一、连接查询查询每个顾客及其购买商品的顾客名称和商品名称。查询“沈阳市”顾客,购买“01”商品的顾客信息。查询“沈阳市”且购买了商品的顾客信息。查询购买“01”商品,且购买数量在2以上的顾客姓名。查询每个顾客购买商品的名称及购买数量和日期。查询购买商品单价超过100的顾客姓名。二、嵌套查询查询与“rose”在同一城市的顾

2、客信息。查询购买商品名称为“面包”的顾客编号和姓名。三、EXISTS查询查询没有购买“ 0001 ”商品的顾客姓名。查询购买了全部商品类别的顾客的姓名。四、实验过程及结果分析一、连接查询查询每个顾客及其购买商品的顾客名称和商品名称,如图1-1所示。select guest.*,guestname,goodsnamefrom guest,goods,purchasewhere guest.guestid=purchase.guestidand goods.goodsid=purchase.goodsid;GUE STICGUESTHAMHG_AGFG_AOl)H硏一知OR KGUESTMAMbG

3、OOD SHAME219统阳三言慧耳tfL623LJ去320北取LJ去1王諦2D宰=王帅U吿52?15A蛭益4211壬种2D-壬帅421士连手机522沈阳向人电脑3 rows selected.图1-1查询“沈阳市”顾客,购买“01”商品的顾客信息,如图1-2所示。select guest.*from guest,purchasewhere guest.guestid=purchase.guestidand g_addr=沈阳and purchase.goodsid=01;佯怔目卄TB14109ord匚作区1, SQL, PL SQL 11 SQLFhj li =-select auest悬f

4、or on gae st t pure ha aewhere gneat. geest id. =pozcrLase. gu eat id and g add勿阳and pure ha as gciDKin 丄日町丄;亦亍)刖制H电)呆书脚电)(取消)GUESTIDGUESTNAMFG.AGFG ADDRG WORK2三宇昔沈阳学生图1-2查询“沈阳市”且购买了商品的顾客信息,如图1-3所示。select guest.*from guest,purchasewhere guest.guestid=purchase.guestid and g_addr=沈阳;连接身份JB14109orcl、清除

5、)T作区输入 SQL, PL SQL 和 SQL Plus 语句。select gues匸*from gue3t,purchasewhere guest gue3tid=purchase guestid and g_addr= :JtPB r ;丸行)l抑载脚本)、保存脚本)I取消)GUESTIDGUESTNAMEG AGEG ADDRG WORK2王宗倉19沈阳学生5令狐静雯22沈阳商人6令狐静雯22沈阳商人图1-3查询购买“01”商品,且购买数量在2以上的顾客姓名,如图1-4所示。select guest.guestname from guest,purchase where purcha

6、se.goodsid=01 and purchase_num2;连接身怡IB14109orcL、清除確区输A SQL, PL SQL 和 SQL*Plus 语句。select guest guestname from guest,purchase where purchase good5id=01 and purchase num2;、执行)J抑载脚本、保存脚本)理消)图1-4查询每个顾客购买商品的名称及购买数量和日期,如图1-5所示。select guest.guestname,goodsname,purchase_num,purchase_datefrom guest,purchase,g

7、oodswhere purchase.goodsid=goods.goodsidand purchase.guestid=guest.guestid;T-作区纭 SQL, PL-Sqt 引讯PhwiF fl :select guest.guestgoadj5En.eH puzcka -_nun puzche:a-_dste fi口皿 芋!皀stF puTckaBe, gaadswhere pur 匚hfi.Hu . goods idg口口cis. gDdidand ptarch n stguest 1 d-autat., gKcaCidj石曲瞰脚杓煤存脚本)單町GUESTNAMFGOODSHA

8、MEPURCHASF_NLMPURCHASEJDATE壬宗看耳机.301-AUG-13-MuS52S-AUG-13LJ盂421-SEP-13uS.321-AUG-11as丄21-FEB-13311-AUG-13王沖521-AUG-13手机425-AUG-13锢1誦匪电諂221-1AN-U9 rows sel&ctedl图1-5查询购买商品单价超过100的顾客姓名,如图1-6所示。select guest.guestnamefrom guest,purchase,goodswhere purchase.goodsid=goods.goodsidand purchase.guestid=guest

9、.guestidand g_price100;T作区sriI? SQL. PL S10&F比厅丿飓脚齐)、規三护木)、=粥图1-6二、嵌套查询查询与“王帅”在同一城市的顾客信息,如图2-1所示。select guest.*from guestwhere guest.g_addr in(select g_addrfrom guestwhere guestname=王帅);清除)1:作区tfiX SQLr FLSQL 和 SQLTNb语句*select guiest, * from guest wtere guesi;in(select g_atSdr xam. guestwhere guest-

10、ajre-1 l)11p(SF)抑翊冲)(保存出杓 (F)GUESTIDGUESTMMEG AGEG_ADDRG_WORK李宁2D-L1王帅2D图2-1查询购买商品名称为“电脑”的顾客编号和姓名,如图2-2所示。select guest.guestid,guestname from guestwhere guest.guestid in(select guestid from purchasewhere purchase.goodsid in (select goodsid from goodswhere goodsname=电脑) );连接身份IB14109ordT作区输入 SQL, PL

11、SQL 和 SQL*Plus 语句。select gu皂吕匸 guestid,gu皂stname from gue3twhere gu.皂日匸.guestid in(s皂丄皂u匸guestidfrom purchase where parch且曰亡.goodsid in(s皂lect goodsid from goods where goo ds name =电.0目 r) );、执行)、抑载脚本)、保存脚本)J药消)GUESTIDGUESTNAME5令狐静委图2-2三、EXISTS查询 查询没有购买“01”商品的顾客姓名,如图3-1所示。select guestnamefrom guestw

12、here not exists(select *from purchasewhere guestid=01);、清除)连接身JB141D9orcl输A. SQL; PL SQL 和 SQLPlus 语句。select gu.e3t:nanie from gue3t where not exist3(select *from purchase where guestid=,011 );、执行)、抑栽脚本)、保存脚本)、取消)图3-1查询购买了全部商品类别的顾客的姓名,如图3-2所示。select guestnamefrom guestwhere not exists(select *from g

13、oodswhere not exists(select *from purchasewhere goodsid=goods.goodsid and guestid=guest.guestid) );连接身份JB14109orcl兀作区输入 SQL, PL JSQ1 和 SQLPlus 语句。、清騎3el皂u匸 guestnamefrom guest where not exists(select *from goodswhere not exists(select *from purchasewhere goodsid=goods.goodsld and guestid=gue3t.guestid)no rows selected图3-2五、成绩评定优良中及格不及格出勤格式内

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 学术论文 > 其它学术论文

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号