Skip to content
Advertisement

How to use SQL to get column count for a previous date?

I have the following table,

Required output,

I am looking to add the price for previous row. Row 1 is 0 because it has no previous row value. Find ratio ie 10/30=0.33

Advertisement

Answer

You can use analytical function ROW_NUMBER and SUM as follows:

DB<>Fiddle demo

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