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

商品基本表:GOODS(G#,GNAME,PRICE,TYPE,FACT),其中属性分别表示商品号,商品名,单价,型号,制造商;
商场基本表:SHOPS(S#,SNAME,MANAG,ADDR),其中属性分别表示商场号,商场名,经历,地址;
销售基本表:SALES(S#,G#,QTY),其中属性分别表示商场号,商品号,销售量。
用SQL语句完成下列要求:
1) 查询销售量在1000到10000之间的销售信息。
2) 查询“青岛海尔集团”制造的商品在“北京东方商厦”的销售情况,包括商 品名,单价、型号、销售量。
3) 查询平均销售量最高的商品号。
4) 删除销售量为空的销售信息。
5) 建立视图S_VIEW,包含地址位于“南京路……”的所有商场信息。

本人邮箱 [email protected]
希望各位大大给予正确的答案

(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 '南京路%'
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-04-08
select * from sales where qty bewteen 1000 and 10000;
select a.gname ,a.price,a.type,c.qty,b.sname from goods a ,shops b,sales c, where a.g#=c.G# and b.s#=c.s# and a.fact='青岛海尔集团' and sname='北京东方商厦';
select * from sales where avg(qty)=(select max(a.aqty) from (select avg(qty) aqty from sales group by g#) a);
delect table sales where qty is null;
相似回答