【问题标题】:Table aliasing in update statement in RedShiftRedShift 中更新语句中的表别名
【发布时间】:2018-10-24 15:49:59
【问题描述】:

我有一个如下的 sql 语句,我正在尝试将其转换为 Redshift。

update #tmpHist l 
set spread = lh.spread
from table1 lh 
where  
    l.id=lh.id 

但它给出的错误是:

[Amazon](500310) Invalid operation: syntax error at or near "l" 

有没有办法在不指定整个表的情况下给表起别名。

【问题讨论】:

标签: sql sql-update amazon-redshift


【解决方案1】:

正确的语法是:

UPDATE table_name SET column = { 表达式 |默认 } [,...]

[来自列表]

[WHERE 条件]

  • 使用FROM 子句加入其他表。

你可以试试这个。

update #tmpHist  
set spread = lh.spread
from table1 lh 
where  
    #tmpHist.id=lh.id 

或者您可以尝试使用update .... join 作为别名。

update l 
set spread = lh.spread
from table1 lh join #tmpHist on l.id=lh.id 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多