【发布时间】:2014-01-09 08:35:03
【问题描述】:
我在 teradata 中创建了一个 SQL 查询,该查询在产品价格发生变化时,但想要显示最新的 - 使用时间戳。然而,问题是数据确实存在 product_number、price、timestamp 精确重复的实例,给出了多个值。我正在寻找消除这些重复项。
select a.product_number, a.maxtimestamp, b.product_price
from ( SELECT DISTINCT product_number ,MAX(update_timestamp) as maxtimestamp
FROM product_price
group by product_number) a
inner join product_price b on a.product_number = b.product_number
and a.maxtimestamp = b.update_timestamp;
【问题讨论】: