需要在mysql介质服务器日志表中找到当前连接

时间:2010-04-21 11:13:45

标签: mysql

我有一个媒体服务器记录到mysql数据库,它为每个连接,播放,停止,断开连接事件记录一个单独的行。我想要做的是找到没有相关断开事件的连接事件或播放没有相关停止事件的事件。

date          time        category    event      clientId    stream    streamId
===============================================================================
2010-04-21    10:30:00    session     connect    1          
2010-04-21    10:30:05    stream      start      1           stream1    1
2010-04-21    10:35:00    stream      stop       1           stream1    1
2010-04-21    10:35:00    session     disconnect 1           
2010-04-21    10:35:00    session     connect    2           
2010-04-21    10:35:05    stream      start      2           stream2    1
2010-04-21    10:35:08    session     connect    3           
2010-04-21    10:35:13    stream      start      3           stream1    1
2010-04-21    10:37:05    stream      stop       2           stream2    1
2010-04-21    10:37:10    stream      start      2           stream1    2

我希望能够获得当前会话的总数,并且在单独的查询中,总共播放当前正在播放的流。

谢谢,

罗杰。

1 个答案:

答案 0 :(得分:0)

我最终使用了复合选择语句。

select * from (select *, (select true from statslog as t1 where t1.clientId = statslog.clientId and t1.event = 'disconnect') as `disconnected`
from statslog where statslog.category = 'session' and statslog.event = 'connect') as t2 where isnull(t2.disconnected);