alternative to lag SQL command
Posted
by
mahen
on Stack Overflow
See other posts from Stack Overflow
or by mahen
Published on 2010-11-23T23:21:47Z
Indexed on
2010/12/30
22:53 UTC
Read the original article
Hit count: 154
I have a table which has a table like this.
Month-----Book_Type-----sold_in_Dollars
Jan----------A------------ 100
Jan----------B------------ 120
Feb----------A------------ 50
Mar----------A------------ 60
Mar----------B------------ 30
and so on
I have to calculate the expected sales for each month and book type based on the last 2 months sales. So for March and type A it would be (100+50)/2 = 75 For March and type B it is 120/1 since no data for Feb is there.
I was trying to use the lag function but it wouldn't work since there is data missing in a few rows.
Any ideas on this?
© Stack Overflow or respective owner