Teradata error : select * must have from clause

Teradata error : select * must have from clause

如何将此 sql 服务器查询转换为 Teradata 查询。这在 Teradata 中不起作用。

select *, 
   (select top 1 endvalue 
    from #AUID 
    where #AUID.adate <= t.adate and #AUID.tid=t.tid 
    order by #AUID.adate desc) as AsD
from History_1 t

当涉及子查询时,您不能简单地使用 *。您应该使用 tablename.* 或 alias.*(如果使用别名)。

select t.*, 
   (select top 1 endvalue 
    from #AUID 
    where #AUID.adate <= t.adate and #AUID.tid=t.tid 
    order by #AUID.adate desc) as AsD
from History_1 t

不过,这会抛出 Failure 6916 TOP N 语法错误:子查询不支持 Top N 选项 错误。

您可以尝试加入表格。

select
    t.*,
    a.endvalue
from 
    History_1 t
left outer join
    #AUID a
on a.tid = t.tid
and a.adate <= t.adate
qualify row_number() over (partition by t.tid, t.adate order by a.adate desc) = 1;  --this ensures you select only one row with max(adate)