BEGIN TRANSACTION;
/* Create a table called NAMES */
CREATE TABLE EVENTS(Id integer, DT date);
/* Create few records in this table */
INSERT INTO EVENTS VALUES(1,'01-01-2017');
INSERT INTO EVENTS VALUES(1,'02-01-2017');
INSERT INTO EVENTS VALUES(1,'03-01-2017');
INSERT INTO EVENTS VALUES(1,'04-01-2017');
INSERT INTO EVENTS VALUES(1,'05-01-2017');
INSERT INTO EVENTS VALUES(2,'01-01-2017');
INSERT INTO EVENTS VALUES(2,'02-01-2017');
INSERT INTO EVENTS VALUES(2,'03-01-2017');
CREATE TABLE LEVEL(Player_id integer,Level integer, DT date);
/* Create few records in this table */
INSERT INTO LEVEL VALUES(1,1,'01-01-2017');
INSERT INTO LEVEL VALUES(1,2,'03-01-2017');
INSERT INTO LEVEL VALUES(1,3,'05-01-2017');
INSERT INTO LEVEL VALUES(2,1,'01-01-2017');
INSERT INTO LEVEL VALUES(2,2,'03-01-2017');
COMMIT;
select * from EVENTS a left join LEVEL b on a.Id=b.Player_id and a.DT=b.DT
Basically whenever level of game will change a record will be pushed into LEVEL table with Date and Current level of game
OUTPUT of above query -
1|01-01-2017|1|1|01-01-2017
1|02-01-2017|||
1|03-01-2017|1|2|03-01-2017
1|04-01-2017|||
1|05-01-2017|1|3|05-01-2017
2|01-01-2017|2|1|01-01-2017
2|02-01-2017|||
2|03-01-2017|2|2|03-01-2017
Output i WANT :
1|01-01-2017|1|1|01-01-2017
1|02-01-2017|1|1|02-01-2017
1|03-01-2017|1|2|03-01-2017
1|04-01-2017|1|2|04-01-2017
1|05-01-2017|1|3|05-01-2017
2|01-01-2017|2|1|01-01-2017
2|02-01-2017|||1|02-01-2017
2|03-01-2017|2|2|03-01-2017
Can somebody help what logic should be used to get the desired output above with SQL
Let me know incase if you need more info