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

一个临时表的小有关问题

2011-12-24 
一个临时表的小问题selecttop5h.Quas数据内容,count(d.HouseID)as成交数量fromHouseshinnerjoinDealsdonh.

一个临时表的小问题
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

数据内容       成交数量                
------   -----------  
闵行区         27                    
长宁区         10                    
浦东新区       7                      
松江区         6                      
虹口区         4      


create   table   #table1
(
  区域   nchar(4),
  成交数   int,
  月份     int
)
我要把上面查出来的值放到一个临时表??怎么做啊??

[解决办法]
declare @temp table(區域 nvarchar(15),成交數量 int 月份 int)

insert into @temp 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

數據不多,就用table變量

热点排行