Teradata 语法:unicode 分隔标识符

Teradata syntax: unicode delimited identifier

我在尝试 运行 Teradata 13.0 中的查询时遇到错误 如何编写此查询?我将此 oracle 查询转换为 Teradata 查询:

select sb.name,
       sb.address1, 
       sb.address2, 
       sb.city, 
       sb.stateprovince,
       sb.postalcode, 
       sb.country, 
       sb.cid, 
       sb.item, 
       sb.mcnum, 
       sb.dmh, 
       sb.hy, 
       sb.firstname, 
       sb.lastname, 
       sb.email, 
       sb.monikerexec, 
       sb.res,
 (select cid from (select * from abc.submissions where res is not null order by res asc) where name = sb.name and item <> sb.item and res < sb.res and rownum =1) as mins,
  (select min(price) from ap.hist where name = sb.name) as minauc,
       sb.cat, 
       sb.uni
 from abc.submission sb
order by sb.item

错误:

听起来问题不在于缺少别名(这是一个问题),而是在子查询中需要 ORDER BY 以便适当的 cid可以在SELECT语句中的第一个子查询minauc中挑出

您可以使用 QUALIFY,而不是执行 ORDER BY 并尝试获取第一条记录,它使用窗口函数来选择您想要的记录:

SELECT 
    sb.NAME, 
    sb.address1, 
    sb.address2, 
    sb.city, 
    sb.stateprovince, 
    sb.postalcode,
    sb.country, 
    sb.cid, 
    sb.item, 
    sb.mcnum, 
    sb.dmh, 
    sb.hy, 
    sb.firstname, 
    sb.lastname, 
    sb.email, 
    sb.monikerexec, 
    sb.res,
    sb2.cid AS mins, 
    (
        SELECT min(price)
        FROM ap.hist
        WHERE NAME = sb.NAME
    ) AS minauc, 
    sb.cat, 
    sb.uni
FROM abc.submission sb
    LEFT OUTER JOIN abc.Submission sb2 ON
    sb.name = sb2.name AND
    sb.item <> sb.item AND
    sb2.res < sb.res AND
    sb2.res IS NOT NULL
QUALIFY ROW_NUMBER() OVER (PARTITION BY sb.name ORDER BY res asc) = 1

这使用 JOIN 将记录放在一起,然后,使用 QUALIFY 只允许通过具有最低 res 的连接记录。