日期:2014-05-18  浏览次数:20439 次

问个存储过程的问题 送分
ALTER   PROCEDURE   App_Unit_Price
@time   int  
--@qu   nchar(4)
AS

create   table   #table1
(
  区域   nchar(4),
  成交数   int
)

--declare   @temp   table(区域   nvarchar(15)   ,成交数量   int)

insert   into   #table1   select   top   5   h.Qu   as   '数据内容 '   ,count(d.HouseID)   as   '成交數量 'from   Houses   h
inner   join   Deals   d   on   h.HouseID   =   d.HouseID
where   h.houseID   in     (select   HouseID   from   Houses)   and  
convert(nvarchar(2)   ,   d.CheckTime   ,   101)   =   @time
Group   by   h.Qu     order   by   Count(d.HouseID)   desc

--上季成交量 
declare   @shjiliang   float
select   @shjiliang   =   count(d.HouseID)   from   Houses   h
inner   join   Deals   d   on   h.HouseID   =   d.HouseID
where   h.houseID   in     (select   HouseID   from   Houses   )   and  
convert(nvarchar(2)   ,   d.CheckTime   ,   101)   =   @time   -   1   and   h.Qu   in   (select   区域   from   #table1)



--总成交量
declare   @total   float
select   @total   =   count(d.HouseID)   from   Houses   h
inner   join   Deals   d   on   h.HouseID   =   d.HouseID
where   h.houseID   in     (select   HouseID   from   Houses)   and  
convert(nvarchar(2)   ,   d.CheckTime   ,   101)   =   @time

--区域成交量
declare   @quliang   float
select   @quliang   =   count(d.HouseID)   from   Houses   h
inner   join   Deals   d   on   h.HouseID   =   d.HouseID
where   h.houseID   in     (select   HouseID   from   Houses   )   and  
convert(nvarchar(2)   ,   d.CheckTime   ,   101)   =   @time   and   h.Qu   in   (select   区域   from   #table1)


declare   @bili   float
select   @bili   =   @quliang   /   @total


declare   @tongbi   float
select   @tongbi   =   (@quliang   -   @shjiliang)   /   @shjiliang   *   100

select   top   5   h.Qu   as   '数据内容 ',   count(d.HouseID)   as   '成交数量 ' ,   @bili   as   '比例 ',@tongbi   as   '同上月增长 '


from   Houses   h
inner   join   Deals   d   on   h.HouseID   =   d.HouseID
where   h.houseID   in     (select   HouseID   from   Houses)   and  
convert(nvarchar(2)   ,   d.CheckTime   ,   101)   =   @time
Group   by   h.Qu     order   by   Count(d.HouseID)   desc


数据内容       成交数量                 比例