我有一个历史表,每当一个记录发生变化时,都要作一shot。 我试图以最初的被俘日期恢复某个历史。 目前,我正在利用这一点:
select
s.Description,
h.CaptureDate OriginalCaptureDate
from
HistoryStock s
left join
( select
StockId,
CaptureDate
from
HistoryStock
where
HistoryStockId in ( select MIN(HistoryStockId) from HistoryStock group by StockId )
) h on s.StockId = h.StockId
where
s.HistoryStockId = @HistoryStockId
这一工作虽然有100万人,但进展缓慢,我无法确定如何优化这一询问。
如何优化这一询问?
www.un.org/Depts/DGACM/index_spanish.htm
WITH OriginalStock (StockId, HistoryStockId)
AS (
SELECT StockId, min(HistoryStockId)
from HistoryStock group by StockId
),
OriginalCaptureDate (StockId, OriginalCaptureDate)
As (
SELECT h.StockId, h.CaptureDate
from HistoryStock h join OriginalStock o on h.HistoryStockId = o.HistoryStockId
)
select
s.Description,
h.OriginalCaptureDate
from
HistoryStock s left join OriginalCaptureDate h on s.StockId = h.StockId
where
s.HistoryStockId = @HistoryStockId
我即将更新该守则,以便使用幼儿教育,但我不太明智,业绩仅略有提高。 任何想法?
仅是另一个说明,我需要查阅历史表中第一个记录,即储存,而不是最早的捕获日期。