用SQL语句建立数据库,帮忙下亚,明天就要交了

题目要求:
某公司的产品销售数据库(ProductSales)有产品表(Product)和销售情况表(Sales),产品表为主表,销售情况表为子表,表结构和存储的数据如下:

主表:Product
ProductID ProductName Price
1 HP1200打印机 2000
2 LX360兼容机 4800
3 IBM 350笔记本 11000
4 BM 360笔记本 12000
子表:Sales
ProductID ClientName ProductNumber SalesPrice
2 流水科技 10 4500
1 流水科技 25 1800
3 联想集团 10 11000
2 联想集团 30 4500
1 联想集团 20 1800
3 北大方正 40 10000
3 诺基亚 20 10500

编写SQL语句实现以下的要求:

 查询出单笔售数量大于15的客户名称、购买数量、销售价格信息;
 查询出所有商品的全部销售金额;
 查询客户姓名、对应客户的销售总金额;
 查询购买过商品“IBM 350笔记本”的商品名称、客户名称、购买数量;
 把客户“流水”名称更新为“ LS”。

要求:

要求创建数据库ProductSales和两个表,编写和调试SQL语句,可以不输入测试数据。

创建数据库
CREATE DATABASE [ProductSales]

创建表
CREATE TABLE Product(ProductID int,ProductName nvarchar(100) ,Price numeric (10, 0) )

CREATE TABLE Sales(ProductID int,ClientName nvarchar(100) ,ProductNumber numeric(10, 0),SalesPrice numeric(10, 0) )

1、查询出单笔售数量大于15的客户名称、购买数量、销售价格信息;
select ClientName,ProductNumber,SalesPrice from Product a,Sales b
where a.ProductID=b.ProductID
and ProductNumber>15

2、查询出所有商品的全部销售金额;
select ProductName,sum(SalesPrice*ProductNumber) as TotalAmount from Product a,Sales b
where a.ProductID=b.ProductID
group by ProductName

3、查询客户姓名、对应客户的销售总金额;
select ClientName,sum(SalesPrice*ProductNumber) as TotalAmount from Product a,Sales b
where a.ProductID=b.ProductID
group by ClientName

4、查询购买过商品“IBM 350笔记本”的商品名称、客户名称、购买数量;
select ProductName,ClientName,ProductNumber from Product a,Sales b
where a.ProductID=b.ProductID
and b.ProductID='3'

5、把客户“流水”名称更新为“ LS”。
update Sales set ClientName=replace(ClientName,'流水','LS')
温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-11-26
..最最简单的方法就是直接在数据库上面建表
然后查看表的属性,就能看到生成SQL语句了/
或者导出数据库 能直接导出所有的生成语句..

select * frm Sales where ProductNumber > 15
select * from Product
select ClientName, ProductNumber* SalesPrice as totalPrice from Sales
select * from Sales where ProductID = 3
update..吃饭去了
第2个回答  2008-11-26
create table PRODUCT
(
PRODUCTID NUMBER not null,
PRODUCTNAME VARCHAR2(100),
PRICE NUMBER,
primary key (PRODUCTID)
) ;

create table SALES
(
SEQ NUMBER not null,
PRODUCTID NUMBER not null,
CLIENTNAME VARCHAR2(100),
PRODUCTNUMBER NUMBER,
SALESPRICE NUMBER,
primary key (SEQ),
foreign key (PRODUCTID)
references PRODUCT (PRODUCTID)
);
1.SELECT t.* FROM sales t WHERE t.productnumber > 15;
2.SELECT SUM(t.salesprice) FROM sales t;
3.SELECT t.clientname,SUM(t.salesprice) FROM sales t GROUP BY t.clientname;
4.SELECT t1.productname,t2.clientname,t2.productnumber FROM product t1,Sales t2 WHERE t1.ProductID = t2.productid AND t1.ProductName = 'IBM 350';
5.UPDATE Sales t
SET t.clientname = (replace(t.clientname,'流水','LS'))
WHERE t.clientname LIKE '流水%';
我上学时也希望有人帮我写作业,唉,知道你的痛苦啊。但我知道这样做是不对的,罪过罪过啊。
第3个回答  2008-11-26
 查询出单笔售数量大于15的客户名称、购买数量、销售价格信息;
select * from sales where ProductNumbe> 15
 查询出所有商品的全部销售金额;
select count(SalesPrice) from sales
 查询客户姓名、对应客户的销售总金额;
select ClientName SalesPrice from sales
 查询购买过商品“IBM 350笔记本”的商品名称、客户名称、购买数量;
select ProductName ClientName ProductNumber from sales where id=3 把客户“流水”名称更新为“ LS”。
update sales set ClientName='LS'

创建表你自己需要自己想,这些对于你学过应该不难. 我虽然可以编写却不能真正帮到你 。
相似回答