Hi Team,
I'm using scripted calculation view and after computation my data in the view/table will be displayed as below and certain cases where there are no transaction happened for that particular week will be displayed as zero.
Col A Col B Col C
1000042965 20090830 15.9
1000042965 20090906 0
1000042965 20090913 0
1000042965 20090920 14.2
1000042965 20090927 0
1000042965 20091004 0
1000042965 20091011 14.4
1000042967 20090830 13.2
1000042967 20090906 0
1000042967 20090913 12.9
1000042967 20090920 0
1000042967 20090927 0
1000042967 20091004 11.2
1000042967 20091011 11.2
but my excepted output is (ie. populate the previous non zero value for the corresponding column)
Col A Col B Excepted Result for Col C
1000042965 20090830 15.9
1000042965 20090906 15.9
1000042965 20090913 15.9
1000042965 20090920 14.2
1000042965 20090927 14.2
1000042965 20091004 14.2
1000042965 20091011 14.4
1000042967 20090830 13.2
1000042967 20090906 13.2
1000042967 20090913 12.9
1000042967 20090920 12.9
1000042967 20090927 12.9
1000042967 20091004 11.2
1000042967 20091011 11.2
I try to implement the logic as below, but I get the error message as sub query cannot correlate with top or order by
SELECT colA, ColB,
(CASE WHEN colC = 0
THEN IFNULL((SELECT colC
FROM TABLE T2
WHERE T1.ColA = T2.colA AND
T2.colB < T1.colB AND
T2.ColC > 0
ORDER BY T2.COLB DESC
LIMIT 1
), 0)
ELSE ColC
END) as ColC
FROM TABLE T1
I try to split the logic and make inner join between 2 statements, still the final output is not desired as above.
Can you please let me know is there any function which will help to overcome this issue? Thanks for your help in Advance!
Regards,
Sathish