Select语句中的Teradata更新表

时间:2012-06-11 20:34:57

标签: sql teradata

如果标题不清楚,请注意。基本上我尝试从多个表中选择某些记录,然后为返回的记录更新某个列值。

T-SQL实施

    UPDATE 
        CUSTOMERS
    SET
        LIKES_US = 'Y'
    FROM
        RESTAURANT REST INNER JOIN CUSTOMERS CUST ON REST.LINK_ID = CUST.LINK_ID
        WHERE
        REST.REST_TYPE = 'Diner' AND CUST.LIKES_US IS NULL

的Oracle

    UPDATE 
       (SELECT CUST.LIKES_US
        FROM CUSTOMERS CUST INNER JOIN RESTAURANT REST ON CUST.LINK_ID=REST.LINK_ID
        WHERE REST.REST_TYPE = 'Diner' AND CUST.LIKES_US IS NULL) NEW_CUST
    SET
        NEW_CUST.LIKES_US = 'Y';

我尝试在Teradata中做同样的事情,就像我在Oracle中做的那样但是我收到以下错误:

Executed as Single statement.  Failed [3707 : 42000] Syntax error, expected something like a name or a Unicode delimited identifier or an 'UDFCALLNAME' keyword between the 'UPDATE' keyword and '('. 
Elapsed time = 00:00:00.003 

STATEMENT 1: Unknown failed. 

我在网上寻找解决方案,但没有运气。

2 个答案:

答案 0 :(得分:9)

您是否尝试过使用Teradata的以下语法:

UPDATE CUSTOMERS C1
  FROM (SELECT C2.LINK_ID
          FROM CUSTOMERS C2
         INNER JOIN RESTAURANTS R2
            ON C2.LINK_ID = R2.LINK_ID
        WHERE R2.REST_TYPE = 'DINER'
          AND C2.LIKES_US IS NULL) D1
   SET LIKES_US = 'Y'
 WHERE C1.LINK_ID = C2.LINK_ID

答案 1 :(得分:1)

我认为在这种特定情况下,下面的查询会表现得更好,因为它需要少一点的连接。

UPDATE C
FROM CUSTOMERS  C, RESTAURANTS R
SET LIKES_US = 'Y'
WHERE 
C.LINK_ID = R.LINK_ID
AND R.REST_TYPE = 'DINER'
AND C.LIKES_US IS NULL