Skip to content
Advertisement

Merge every 2 consecutive records into 1

I have a pre-processed table which I want to group every pair into one record containing data from fields of both records.

The query should return:

You can safely assume that every 2 records is the correct pair (events are Start and End respectively, and User is the same) since the table is pre-filtered.

EDIT: Sorry, I forgot to mention that having multiple pairs for a single user is allowed. I’ve adjusted the example table above to show that.

Advertisement

Answer

As suggested, this should do what you want :

EDIT : As a user id can appear multiple times, in multiple groups, see the following query :

WITH DEMO HERE

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement