 Hello, welcome to SSU-Retake, Sushil this side and this is continuation of Sikosower interview questions and answers. So, today we are going to discuss one more interview question that is previous null values and this question was asked in essential. So, one of my friend has attended interview with the essential. So, this question was asked over there. So, let's move to next slide to understand about the question. So, here as we can see we have an input table that would have three columns first is sequence combo then id then name. In the output we are also getting all these columns but in the input as we can see for sequence 2 we are getting null. For sequence 4 and 5 again we are getting null. So, if we are getting any null value then that null value will be replaced by last not null as we can see in case of sequence 2 it is null. So, last not null value is 10. So, this null will be replaced by 10 in the output. Then for id 4 and id 5. So, these two are null values. So, last not null value is 20. So, 20 will be replaced instead of these two null. So, how we can write the query for getting this output. So, let's move to sequence over management studio where we will write the query for getting the output. So, as I am using SQL 2017 you may have another version of sequence over. So, first of all I would like to execute this create table statement to create the table. So, command completed successfully. So, table is created. Next, I just want to insert data on this table. So, we can execute this insert statement to insert the data into the table. So, 6 rows were created. So, data is inserted successfully. Now, I just want to check the data. So, select Aztec from our table that is previous null value now. So, as we can see we are getting the same meta data. So, before going to write the query let's understand about the logic. So, how we can replace these null values by last not null values. So, go to on excel to understand about the logic. So, as we can see first three columns are coming from input table then I just want to create a partition number. So, this partition value will be started from one and will be increased one by one. So, here for sequence one it is one. If we will get any null value after that not null value then this partition value will not be going to increased. So, it remains same as we can see for sequence one and two it is one. If we will get any not null value in the next value then this partition value will be increased by one. As we can see in the sequence three we are getting two for four five. So, these two are null. So, this partition value will not be going to increased. So, it remains same that is two. Then here we are getting the not null value. So, this partition value will be increased by three. Then this is a new ID. So, what would be the concept for this new ID. So, in the new ID we just want to get the first value according to partition value like here we are having this value. So, first value of this ID would be 10. So, 10 will be used in these two rows. For two it is having three rows. So, first value will be 20. So, 20 will be used for two then 30. So, this logic will be used for getting the output. So, go to one sequence over and now I just want to write the logic. So, first I just want to get the sequence number. After that we just want to get the ID and then name. And here I just want to use the sum function and here I need to check case when this ID is null or not. If this value is null then 0 as 1. So, this is for this sum function. So, over clause can be used with the sum function after 2k12. So, I am going to use the over clause and here let me order by with sequence. Now let me call this column as value partition. Now we can execute this query. So, here we are getting the partition values as we were seeing in the excel. So, let me put this into a cd and then I just want to get the first value as I told you. So, we can use this cd and then I just want to get the sequence number after that ID to compare with the new ID then the name and now we can use the first value. So, this is the first value and we just want to get the first value from this ID and we can use all and here we have to use the partition by with this newly column which is value partition. Now we can use the order by clause and this order by clause will be used for this sequence. Now let me call this as new ID. So, this is new ID. Now let me execute query and check the output. So, here we are getting 10 then 10 then here we have null values. So, 20 and 20. So, null values is replaced by previous not null values. So, I hope you have understand how we can write the query for getting the output. If you like this video please subscribe our channel to get many more videos. Don't forget to press the bell icon to get the notification of all newly uploaded videos and if you need this script it will be available on the description of this video. So, you can copy from there. Thank you so much for watching.