دنبال کننده ها

۱۳۹۶ اسفند ۱۰, پنجشنبه

sql - How to put 0 for all the months for a particular composition of key in table

[ad_1]



I have a sample Table :



Month Id1 Id2 Id3 value 

May-18 1 1 1 10
Sep-18 1 1 1 20


I wanted to lead and lag function , for eg .



The output should be using lag:



Month Id1 Id2 Id3 value 
May 1 1 1 0(March)+0(April)+10(May)


In current situation if I use lag then it shows wrong output as there is no value for month of March and April .



How do I tailor make it as :



Month Id1 Id2 Id3 value 

Jan-18 1 1 1 0
Feb-18 1 1 1 0
Mar-18 1 1 1 0
Apr-18 1 1 1 0
May-18 1 1 1 10
Jun-18 1 1 1 0
Jul-18 1 1 1 0
Aug-18 1 1 1 0
Sep-18 1 1 1 20
Oct-18 1 1 1 0
Nov-18 1 1 1 0
Dec-18 1 1 1 0



[ad_2]

لینک منبع