Suppose I am storing events
associated with users
in a table as follows (with dt
standing in for the timestamp of the event):
For Oracle (version 11g R2):
By chance if you are using Oracle DB 11g R2, take look at listagg. The below code should work, but I haven't tested. The point is: you can use listagg
.
SQL> select user,
2 listagg( event, '' )
3 within group (order by dt) events
4 from users
5 group by user
6 order by dt
7 /
USER EVENTS
--------- --------------------
1 ADBCB
2 BBAAC
In prior versions you can do with CONNECT BY clause. More details on listagg.