第一范文网 - 专业文章范例文档资料分享平台

数据库原理与应用课程 实验指导书(附答案)

来源:用户分享 时间:2025/7/24 4:27:21 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

数据库原理与应用课程实验指导书

insert into CP

values('','微波炉',1000,100,NULL)

insert into CP

values('','抽油烟机',1200,50,NULL)

alter table CP

add 产品简列 varchar(50)

update CP

set 价格=价格*0.8

delete from CP

where 价格*0.9<1500

实验四: 1.

select 产品编号,产品名称,价格 from CP

select 客户编号 as 'Customer id' ,客户名称 as 'Customer name' from XSS

where 地区='南京'

select 产品编号,产品名称,评价= case

when 价格<1000 then '廉价产品'

when 价格>=1000 and 价格<2000 then '一般产品' when 价格>=2000 and 价格<3000 then '昂贵产品' else '很昂贵产品' end from CP

select 产品编号,产品名称,产品总值=价格*库存量 from CP

select 客户编号 from CPXSB

group by 客户编号

having count(产品编号)>=1

37

select * from CP

where 价格>1000 and 价格<2000

select * from CP

where 产品名称 like '冰箱_A' 2.

select 总价格=sum(价格) from CP

select 产品编号 ,sum(销售额) 销售额 from CPXSB

where 销售日期='2004-3-18' group by 产品编号

select 客户编号 from CPXSB

group by 客户编号

having count(产品编号)>=2

实验五

1.查询在2004年3月18日有销售的产品名称(不允许重复)。 SQL标准语句:

select distinct 产品名称 from CP,CPXSB

where CP.产品编号=CPXSB.产品编号 and 销售日期='2004-3-18'

T-SQL扩展语句: select distinct 产品名称 from CP inner join CPXSB

on CP.产品编号=CPXSB.产品编号 and 销售日期='2004-3-18'

2.查询名称为“家电市场”的客户在2004年3月18日购买的产品名称和数量。 SQL标准语句: select 产品名称,数量 from CP,XSS,CPXSB

where CP.产品编号=CPXSB.产品编号 and XSS.客户编号=CPXSB.客户编号

38

数据库原理与应用课程实验指导书

and 销售日期='2004-3-18' and 客户名称='家电市场'

T-SQL扩展语句: select 产品名称,数量 from CP inner join CPXSB

on CP.产品编号=CPXSB.产品编号 and 销售日期='2004-3-18' inner join XSS

on XSS.客户编号=CPXSB.客户编号 and 客户名称='家电市场'

3.查找所有产品情况及销售他们的销售日期、购买他们的客户编号和数量, 若产品没有销售记录,也要包括其情况。 select CP.*,销售日期, 客户编号,数量 from CP left outer join CPXSB

on CP.产品编号=CPXSB.产品编号

4.查找所有购买情况,若客户没有购买产品,也要包括其情况。 select XSS.*,产品编号,销售日期,数量,销售额 from CPXSB right join XSS

on XSS.客户编号=CPXSB.客户编号

实验六

查询在2004年3月18日没有销售的产品名称(不允许重复)。 用IN子查询:

select distinct 产品名称 from CP

where 产品编号 not in

(select 产品编号 from CPXSB where 销售日期='2004-3-18')

用EXISTS子查询:

select distinct 产品名称 from CP

where not exists (select * from CPXSB

where 销售日期='2004-3-18'and CP.产品编号=CPXSB.产品编号 )

查询名称为“家电市场”的客户在2004年3月18日购买的产品名称和数量。 用IN子查询:

select 产品名称,数量 from CP,CPXSB

39

where 客户编号 in

( select 客户编号 from XSS where 客户名称='家电市场' )

and 销售日期='2004-3-18' and CP.产品编号=CPXSB.产品编号

用EXISTS子查询:

select 产品名称,数量 from CP,CPXSB

where CP.产品编号=CPXSB.产品编号 and 销售日期='2004-3-18' and exists (

select * from XSS where 客户名称='家电市场'and XSS.客户编号=CPXSB.客户编号 )

查询销售量大于所有2004年3月18日销售的各产品销售数量的产品编号。 用ALL谓词:

select 产品编号 from CPXSB group by 产品编号 having sum(数量)>all

(select sum(数量) from CPXSB where 销售日期='2004-3-18' group by 产品编号 )

查询购买了所有产品的客户的名称。 select 客户名称 from XSS

where not exists (

select * from CP where not exists (

select * from CPXSB

where 产品编号=CP.产品编号 and 客户编号=XSS.客户编号 ) )

查询购买了客户编号为“”的客户购买的所有产品的客户的名称。

40

数据库原理与应用课程 实验指导书(附答案).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c5iehb8ugy28wrp7230mk0mq5e7eayt01813_11.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top