云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 数据库原理与应用课程 实验指导书(附答案)

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

  • 62 次阅读
  • 3 次下载
  • 2025/6/5 12:26:12

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

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

  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

数据库原理与应用课程实验指导书 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

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com