请问一个简单的表合并问题?
select StationNum,ObservTimes,MaxTemp from tabtimedata where ObservTimes= '2007042308 '
select StationNum,sum(cast(Precipitation as float)) as SumR from tabtimedata where ObservTimes> '2007042305 ' and ObservTimes <= '2007042310 ' group by StationNum
StationNum ObservTimes MaxTemp
---------- ----------- -------
59855 2007042308 284
59845 2007042308 292
59851 2007042308 274
(所影响的行数为 20 行)
StationNum SumR
---------- -----------------------------------------------------
59851 0.0
59845 1.0
59855 0.0
我现在想写成这样应该怎么写?即把两个表合并
StationNum ObservTimes MaxTemp SumR
59855 2007042308 284 0.0
59845 2007042308 292 1.0
59851 2007042308 274 0.0
------解决方案--------------------select A.StationNum,ObservTimes,MaxTemp,SumR from
(select StationNum,ObservTimes,MaxTemp from tabtimedata where ObservTimes= '2007042308 ') A
Inner Join
(select StationNum,sum(cast(Precipitation as float)) as SumR from tabtimedata where ObservTimes> '2007042305 ' and ObservTimes <= '2007042310 ' group by StationNum) B
On A.StationNum=B.StationNum
------解决方案--------------------create table #t
select StationNum, ObservTimes, MaxTemp,SumR into #t from table1 t1,table2 t2
where t1.StationNum=t2.StationNum