Saturday, 15 January 2011

sql - How can I add a running total of one column to an Access query? -



sql - How can I add a running total of one column to an Access query? -

i have query contains in 1 field percentage of total sales corresponding specific product in past 12 months. example:

product 1 - 38% product 2 - 25% product 3 - 16% (...)

the records sorted in descending order percentage column, , sum of has 100%. want create new column adds previous percentages running total, this:

product 1 - 38% - 38% product 2 - 25% - 63% product 3 - 16% - 79% (... until reaches lastly product , 100% sub-total)

how this?

if have id field, or date field, can utilize variation of correlated subquery.

select t.*, t.productpct+[prev_value] runningsum, (select sum([productpct]) test t2 t2.id < t.id ) prev_value test t;

there people way improve @ sql i, if helps or gives reply great.

sql ms-access access-vba ms-access-2007

No comments:

Post a Comment