SAS / SQL使用Teradata.UPDATE语法

时间:2015-05-19 10:34:40

标签: sql teradata

我有一个临时表“temp”,我有一些数据,我希望用另一个表ip_geo_data_location映射。我希望从另一个表中生成temp_id的location_id以及如下所述的条件: 错误如下:“错误:Teradata执行:应使用定义的别名,而不是表名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;

2 个答案:

答案 0 :(得分:0)

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;

答案 1 :(得分:0)

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

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
;