您可以通过创建使用窗框组 (GUWF) 来尝试以下查询。来源链接 https://www.red-gate.com/simple-talk/sql/t-sql-programming/filling-in-missing-values-using-the-t-sql-window-frame/.
create table MyTable ([dtDate] date, Cost decimal(18, 6))
insert into MyTable values
('2017-01-01', 18.6046511),
('2017-01-03', 22.9787234),
('2017-01-03', NULL),
('2017-01-12', 18.8584937),
('2017-01-16', 19.1827852),
('2017-01-16', NULL),
('2017-01-19', NULL),
('2017-02-21', NULL),
('2017-03-04', 24.0597622),
('2017-03-28', NULL),
('2017-04-17', 33.5398414),
('2017-04-17', NULL)
SELECT dtDate, Cost = MAX(Cost) OVER (PARTITION BY c)
FROM
(
SELECT dtDate, Cost
,c = count(Cost) OVER (ORDER BY dtDate)
FROM MyTable
) a
ORDER BY dtDate;