|
No, not unless you include cursors, which I always mentally assign to the
programming language side of the fence and not the SQL side.
If you don't want to join the table to itself 40 times
(and who would?), then just run a simple query with an ORDER BY,
and do current/previous logic using a cursor
or by looping over the result set in your programming language.
Unless you're on Sybase. Sybase Adaptive Server Anywhere
(but not Adaptive Server Enterprise) has this really
neat, albeit proprietary, non-standard aggregate function called
list(). What it does is produce a comma-separated list of all
the non-null values in a column for each group in a GROUP BY query.
So your query would be:
select id, name, list(holding)
from yourtable
group
by id, name
Gorgeous, isn't it?
|