如何更新 Teradata 中的前 1 条记录

how can I update a top 1 records in teradata

我正在尝试根据他们的任期更新第一条记录俱乐部代码 + 活动代码 + 地区。 (Tereneyears 导致重复记录,但我需要它们)

这适用于 T-SQL 但不适用于 Teradata

update MYTable
set qtyupdate =(SELECT quantity
  FROM codes
  WHERE MYTable.clubcode=codes.clubcode 
        AND MYTable.campaigncode=codes.campaigncode
        and MYTable.region=codes.region)
where identity_column in (select top 1 x.identity_column from MYTable X where x.qtyupdate = MMYTable.qtyupdate order by x.tenureyears)

它只更新 table 上的 1 条记录,我也收到错误 3706 cannot use order by in subqueries。

如果您的示例有效,它只会更新 1 行(即使在 T-SQL 中),因此您的问题并不完全清楚。也许是这样的?

update MYTable q
set qtyupdate =(
    SELECT  c.quantity
      FROM  codes c
      WHERE q.clubcode=c.clubcode 
            AND q.campaigncode=c.campaigncode
            and q.region=c.region)
where   identity_column in
 (
    select  z.identity_column 
    from    (
         select x.identity_column, x.qtyupdate,
         rank() over (order by x.tenureyears) as rnk 
        from    MYTable X 
    ) z
    where   z.rnk=1
    and z.qtyupdate = q.qtyupdate 
);