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