July 23, 2009 at 9:26 am
Hi everyone, I really hope that someone can help me out.
I have two tables Categories and Values.
The Values table has a column called Sequence which is an int and another decimal column called value.
What I need is a query which produces a row for every sequence value within each category, a cumulative sum of the value field, ordered by sequence.
Is this possible and what would be the most efficient way to go about doing this?
Thanks a lot everyone,
Martyn.
July 23, 2009 at 9:52 am
you could use something like this:
select c.category,v.sequence,sum(v.value)
from Categories c, [Values] v
where v.category = c.category
group by c.category,v.sequence
order by v.sequence
Categories:
Category Description
1 Cat 1
2 Cat 2
3 Cat 3
Values:
ID Cat Seq Value
1115.00
2122.50
31220.00
42110.00
5235.00
63150.00
Results =
Category Sequence Sum(Value)
1 1 5.00
2 1 10.00
3 1 50.00
1 2 22.50
2 3 5.00
Is this what you need?
July 23, 2009 at 1:32 pm
It looks like Doug has provided you with a solution, I'd just change it to ANSI join syntax.
For future posts you should read the first article linked in my signature. Posting that way helps us better understand what you need and provide tested solutions.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply