数据库原理问题 已知某数据库系统中包含如下三个基本表:

数据库原理问题 已知某数据库系统中包含如下三个基本表:,第1张

(1)select * from sales where qty between 1000 and 10000

(2)select gname,price,type,qty

from goods,sales

where goods.g#=sales.g# and fact='青岛海尔集团' and s# in(select s# from shops where sname='北京东方大厦')

(3)select g#

from (select g#,max(a.aqty) from (select g#,AVG(QTY) as aqty from sales group by g#) as a

group by g#) as b

本来这题用top 做简单、但是考虑到有销售量相同的、还是用上面这个

(4)delete from sales where qty is null

(5)create view S_VIEW

as

select *

from shops

where addr like '南京路%'

--客户表Customers

create table Customers

(

客户ID int primary key,

客户姓名 varchar(20) not null,

客户公司 varchar(20),

库存 varchar(200),

客户电话 varchar(16) check(客户电话 like '123[0-9]{4}')

)

--订单表Orders

create table Orders

(

客户ID int,

产品ID int ,

产品名称 varchar(20)not null,

定货数量 int not null,

总金额 decimal(8,2) not null,

下单时间 datetime not null ,

foreign key (产品ID) references Products(产品ID),

foreign key (客户ID) references Customers(客户ID)

)

--产品表Products

create table Products

(

产品ID int primary key,

产品名称 varchar(20) not null,

产品单价 decimal(5,2),

库存量 int

)

--(1)请根据客户表Customers的结构说明,用T-SQL语言创建该表(已创建)

--(2)查询订单表Orders中下单时间在‘2012-01-01’至’2012-12-31’之间的客户ID,产品名称,定货数量和总金额

select 产品名称,定货数量,总金额 from Orders where 下单时间 like '2012%'

--(3)查询产品表Products中产品单价的最大值、最小值及平均值,并分别使用别名来显示结果

select max(产品单价) as 单价最大值,min(产品单价) as 单价最小值,avg(产品单价) as 单价平均值 from Products

--(4)创建名为v_cus_pro_ord的视图,获取总金额不小于5000的客户ID、客户名称、产品ID、产品名称、产品单价、定货数量、总金额及下单时间

create view v_cus_pro_ord as

select o.客户ID,c.客户姓名,o.产品ID,o.产品名称,p.产品单价,定货数量,总金额,下单时间 from Orders o,Products p,Customers c

where 总金额 >=5000 and o.客户ID=c.客户ID and o.产品ID=p.产品ID

如有不懂,请继续追问


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9991944.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-04
下一篇 2023-05-04

发表评论

登录后才能评论

评论列表(0条)

保存