create proc p6
as
--该存储过程显示哪个商品销路最好
begin
create table #temp
(
productid int,
saled money
)
insert into #temp select productid,sum(unitprice*quantity*discount) as saled from [order details] group by productid
--saled计算列单价乘以数量乘以折扣
--上面语句select后面的语句即求所有商品的 销售金额
select * from #temp where saled in (select max(saled) from #temp)
--将上面语句的max换成min则求出销路最差的商品
end
--drop proc p6
exec p6
as
--该存储过程显示哪个商品销路最好
begin
create table #temp
(
productid int,
saled money
)
insert into #temp select productid,sum(unitprice*quantity*discount) as saled from [order details] group by productid
--saled计算列单价乘以数量乘以折扣
--上面语句select后面的语句即求所有商品的 销售金额
select * from #temp where saled in (select max(saled) from #temp)
--将上面语句的max换成min则求出销路最差的商品
end
--drop proc p6
exec p6