SAS/SQL 使用 Teradata.UPDATE 语法

SAS/SQL Using Teradata.UPDATE syntax

我有一个临时的 table "temp",我有一些数据希望与另一个 table ip_geo_data_location 映射。我希望从另一个 table 中生成临时 location_id 以及以下提到的条件: 错误如下:"ERROR: Teradata execute: Alias name defined should be used instead of table name temp."

update temp
from temp a, ip_geo_data_location b
set a.location_id=b.location_id
where a.ablock=b.ip_start_1
and a.bblock=b.ip_start_2
and a.ip_integer between b.ip_start and b.ip_end;
UPDATE a
FROM temp a, ip_geo_data_location b
SET a.location_id = b.location_id
WHERE a.ablock = b.ip_start_1
AND a.bblock = b.ip_start_2
AND a.ip_integer BETWEEN b.ip_start AND b.ip_end;

有时我发现更新语法有点混乱,因此将更新写成子查询会有所帮助。

update temp
from
(
  select
  a.location_id
  ,a.ablock
  ,a.bblock
  ,a.ip_integer
  from temp as a

  inner join ip_geo_data_location as b
  on b.ip_start_1 = a.ablock
  and b.ip_start_2 = a.bblock
  and a.ip_integer between b.ip_start and b.ip_end
)sub
set location_id = sub.location_id
where temp.ablock = sub.ablock
and temp.bblock = sub.bblock
and temp.ip_integer = sub.ip_integer
;