Svend,
If you are using an Oracle database, then it has this capability built-in in the form of
analytic functions.
Just do an internet search for "analytic functions" and you will find
lots of information.
To get you going, the below URL is the result of my search:
http://tinyurl.com/8mbnz Good Luck,
Avi.
P.S. If you're not using Oracle, I guess the above is a waste of your time. Maybe next time
you should mention what database you are using.