I need to calculate Months Sales Outstanding.

CREATE TABLE  AR
    Cust    Text
    AR    Double

CREATE TABLE Sales
    Cust    Text
    Per    Integer -- runs 1, 2, 3, etc
    Sales    Double 


The calculation is that for each customer: 
MSO = (Per + (AR-sum(Sales)/Sales))    
    Where Per and Sales are for the lowest 
    Period where Sum(Sales) is greater than the AR 

So 

AR
Cust        AR
000001    100
000002     50

Sales
Cust        Per    Sales
000001    1    60
000001    3    60
000001    4    60
000002    1    15
000002    2    15
000002    3    15
000002    4    15

Result
Cust        MSO
000001    2.3   = (3+(100-120)/60))
000002    3.3   = (4+(50-60)/15))

    Hopefully I described that in a meaningful way. Is it possible to do that 
efficiently or at all using SQL?

Thanks,
David
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to