Calculating Over Top N Values Per Group
===

I have a access table with time series data like this:

    loc | date | value
    A    2/11/07 50
    A    2/12/07 45
    A    2/13/07 23
    B    2/11/07 34
    B    2/12/07 46
    B    2/13/07 56
    C   ....... ...
    ...
    D..........
    .....

And i want to get the Z, (value - avg(values)/stDev(values), values of each group over different time periods so the 20 z values would consider values over the last 20 days, the 60 day over the last 60 days etc. And i also want to select the z values on the latest day so the result would look like this:

    loc | date | value | 20Day zValue | 60Day ZValue | 120 day Zvalue
    A   2/13/07   23       .04           .09            .6
    B   2/13/07   56         .87         .54            .96
    C .....................

  
