Dear colleagues, currently I am facing a complex escenario related with gaps and sequences, but I was trying with diferent cases but I did not get the correct results, I am sure about the use of windows functions, but I would like a little help. I have a table with the information grouped by PublicationId, Provider, MetricId and Amount by Date, one row by each month, but in some cases these data don't have a sequencial values, for example I have the data for the next sequence:
I need to get the sequence by each month, in this case I need to project the month from February to May (with the last previous value, for this case of January) , this is:
The data for testing are:
DECLARE @PublicationsByUser AS TABLE(
Id INT,
PublicationId INT,
MetricId INT,
ProviderId INT,
DateCreated DATE,
Amount FLOAT
);
INSERT INTO @PublicationsByUser
VALUES (1,1,1,1,'20150101',10),
(2,1,1,1,'20150201',15),
(3,1,1,1,'20150401',20),
(4,1,1,1,'20150501',20),
(5,1,1,1,'20150801',25),
(6,1,1,1,'20150101',10),
(7,2,1,1,'20150101',1),
(8,2,1,1,'20150601',6);
SELECT * FROM @PublicationsByUser
Thank you for your help.