【发布时间】:2017-07-23 11:25:12
【问题描述】:
我有一个Products 表,其中包含以下列
ProductId - INT - PK
Name - Varchar
Price Decimal
我还有一张桌子ProductPriceHistory
当产品价格更新时,我使用触发器将旧价格和新价格存储在该表中。此表有以下列
ProductPriceHistoryId
Name
OldPrice
NewPrice
UpdateDate
我可以根据Name 列加入此表。
现在的问题是,在我的结果集中 - 我想获得 Product.Name、Product.Price 和(用于获取表 ProductPriceHistory 中的最后更新值)ProductPriceHistory.NewPrice。
挑战在于,在历史表中,我根据不同的日期为每个产品有很多行。对于每个产品,我需要从为该产品存储的最新行中获取信息。
【问题讨论】:
标签: sql stored-procedures ranking