更改 oracle sql 中 link 的第一条记录的日期

Change the date for the 1st record of a link in oracle sql

我想将产品的第一条记录的 SALES_DATE 更改为 '01.01.1800'。这意味着我想获取存储在 PRODUCT_ID 中的所有唯一产品并检查加载产品的第一个 SALES_DATE 并将此 SALES_DATE 更改为 '01.01.1800'。我相信我可以使用 RANK 函数,但我以前没有使用过,可能还有另一个很好的解决方案,我正在尝试为此编写查询。 PRODUCT_ID 值在此列中不是唯一的。

Select PRODUCT_ID,SALES_DATE from SALES_DETAILS

无需 RANK,您可以使用相关子查询获取最低日期:

select *
from sales_details as sd
where sales_date <> date '1800-01-01' -- don't update if there's already a row with that date
  and sales_date = -- find the row with the lowest date
      ( select min(sales_date)
        from sales_details as sd2
        where sd.product_id = sd2.product_id
      )

当您检查它是正确的数据时,只需切换到更新: