更新左外连接的表

时间:2016-08-04 04:29:11

标签: sql-server tsql

有没有人知道更新左外连接表的好参考?

在执行左外连接然后填充列之前,是否创建了我想要存储的列?

我希望将segmentpatialdata存储在一个新表中,或者将一行添加到包含来自segmentspatialdata的值的现有表中,但是如果我这样做的话,我不确定insert语句的位置。

SELECT 
    a.rowid,
    a.Season,
    a.Name,
    a.Latitude,
    a.Longitude,
    b.rowid,
    b.Season,
    b.Name,
    b.Latitude,
    b.Longitude,
    CAST('LINESTRING(' +  a.Longitude  +' '+ a.Latitude  +', '+ 
    b.Longitude  +' '+ b.Latitude  + ')' AS GEOGRAPHY) AS segmentspatialdata
FROM 
    hurracane a
LEFT OUTER JOIN 
    hurracane b

ON     
    b.rowid = a.rowid + 1 
    AND b.season = a.season
    AND b.name = a.name

WHERE 
    b.rowid IS NOT NULL   
ORDER BY a.rowid

1

1 个答案:

答案 0 :(得分:0)

其中b.rowid不是NULL
使它成为常规联接

insert into table (segmentspatialdata)   
SELECT CAST('LINESTRING(' +  a.Longitude  +' '+ a.Latitude  +', '+ 
b.Longitude  +' '+ b.Latitude  + ')' AS GEOGRAPHY) AS segmentspatialdata
FROM 
    hurracane a
join 
    hurracane b
     ON b.rowid = a.rowid + 1 
    AND b.season = a.season
    AND b.name = a.name