Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How many times do two events happen at the same time

Status
Not open for further replies.

elsenorjose

Technical User
Oct 29, 2003
684
US
Apologies in advance if this is convoluted, I'll do my best to explain. Given the sample data below I need to know how many times a group of timestamps and player ids have a play/stop pair. The question being asked of me is how often does a player send a play/stop event pair at the same time. My answer in this sample is 3. The last record is a standalone play event.

1188082370 8093371429477036616 play
1188082370 8093371429477036616 stop
1188082370 8093371429477036616 play
1188082386 7586439231527335752 play
1188082386 7586439231527335752 stop
1188082386 7586439231527335752 play
1188082393 8236898361920600390 play
1188082393 8236898361920600390 stop
1188082394 8236898361920600390 play
 
Hello,

this problem begs for an intersect function, that may be available in a future release of Mysql. For now you have to use a workaround like this (not tested):

select count(*) from
(
select distinct time_st, player_id from my_table a
where event = 'play'
and exists
(select * from my_table b
where event = 'stop' and
a.time_st = b.time_st
and a.player_id = b.player_id)
)


hope this helps
 
Thanks! I'll give that a try and post back my results. For now, the engineer did it in Perl...which he should have done in the first place ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top