数据量在15万左右,我这个SQL跑的时间比较长,能否优化一下,谢谢。
select TIMESTAMPDIFF(SECOND,a.time,b.time) as online_time,a.time as login_time,b.time as logout_time,a.cid,a.pid from
(select time,cid,pid from eventstats where event = 'login') as a,
(select time,cid,pid from eventstats where event = 'logout') as b
where a.cid = b.cid
select TIMESTAMPDIFF(SECOND,a.time,b.time) as online_time,a.time as login_time,b.time as logout_time,a.cid,a.pid from
(select time,cid,pid from eventstats where event = 'login') as a,
(select time,cid,pid from eventstats where event = 'logout') as b
where a.cid = b.cid
from eventstats a , eventstats b
where a.cid = b.cid
and a.event = 'login'
and b.event = 'logout'