Skip to content
Advertisement

Get the data from previous month in sql query

I have a data of all the cost for each month. For example,

I have table of cost for each month

Then what I want in the output for every month that is = ‘0’, it will get the data in the previous month and so on until it’s not equal = ‘0’

Is this possible using oracle sql or using xml.

I tried the oracle sql query below, for example is I want the value of April to be = 899.20

I used the case when condition,

and in XML is the if else condition

But both conditions I know didn’t work. Please help

Thank you

Advertisement

Answer

You can use:

Which, for the sample data:

Outputs:

   JAN |    FEB |    MAR |    APR |    MAY
-----: | -----: | -----: | -----: | -----:
 899.2 |  899.2 |  899.2 |  899.2 |  899.2
439.38 | 485.29 | 485.29 | 485.29 | 482.29

db<>fiddle here

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement