sql - How to merge last two events into one row -




i have table below.

date         id    event      keyword   val     pattern_id() 2017-08-01   001   triggerx   abc       (null)  1 2017-08-01   001   triggery   (null)     3      1 2017-08-01   009   triggerx   cde       (null)  2 2017-08-01   010   triggerx   ghi       (null)  3 2017-08-01   010   triggerx   ghi       (null)  3 2017-08-01   010   triggerx   ghi       (null)  3 2017-08-01   010   triggery   (null)     1      3 (list continues..) 

event triggerx followed triggery (not vice versa). there chance there triggerx (no triggery) id 009. however, there no chance triggery only.

what i'd following.

for example of id 001, i'd merge triggerx keyword column , triggery val column 1 row.

for example of id 010. has 4 events, need last 2 events (last triggerx , y) , merge keyword column , val column. give me below.

date        id   keyword   val 2017-08-01  001  abc       3 2017-08-01  010  ghi       1 

could me figure out how construct sql result above?

i think want:

select date_id, id, max(event), max(keyword) t keyword in ('triggerx', 'triggery') group date_id, id having count(distinct keyword) = 2; 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -