首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

问个存储过程的有关问题 送分

2012-03-25 
问个存储过程的问题 送分ALTERPROCEDUREApp_Unit_Price@timeint--@qunchar(4)AScreatetable#table1(区域nc

问个存储过程的问题 送分
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


数据内容       成交数量                 比例                                                 同上月增长                                          


------   -----------   -------------------------   -------------------------  
闵行区         27                     0.9                                               170                                              
长宁区         10                     0.9                                               170                                              
浦东新区       7                       0.9                                               170                                              
松江区         6                       0.9                                               170                                              
虹口区         4                       0.9                                               170          

我希望一个区算自己的,?但是老是出来只算一个的。


[解决办法]
一个区算自己的......................................................................
没明白.
[解决办法]
涉及的字段太多了,眼都看花了,帮顶

热点排行