I have an order table with a column indicating buy or sell, with rows usually ordered by timestamp. What I would like to do is work with consecutive purchase groups and also sell them. egB B S B S B B S -> (B B S) (B S) (B B S)
Example:
order_action | timestamp
-------------+---------------------
buy | 2013-10-03 13:03:02
buy | 2013-10-08 13:03:02
sell | 2013-10-10 15:58:02
buy | 2013-11-01 09:30:02
buy | 2013-11-01 14:03:02
sell | 2013-11-07 10:34:02
buy | 2013-12-03 15:46:02
sell | 2013-12-09 16:00:03
buy | 2013-12-11 13:02:02
sell | 2013-12-18 15:59:03
In the end, I will run the aggregation function (the groups are that I can exclude the whole group based on its sales order), so GROUP BYeither split windows looked like the right way, but I canβt figure out how to get this particular group.
source
share