我有这个表日志:
ID - MACDevice - USERNAME - startDateTime - stopDateTime - Duration
我需要用统计数据填写下表:
MACDevice - MAXConcurrentConnection - DateTimeOccurred
我只需知道每个MacDevice的并发连接(时间和数量)的最大值,如果需要,监控的时间间隔可能是10分钟,当我运行查询时(每月一次)我只想查询新的日志值并仅在greatear而不是存储的值时存储它们。 欢迎任何帮助 谢谢 LUC
答案 0 :(得分:0)
SELECT MACDevice, MAX(ConcurrentConnections) AS MAxConnections
FROM
( SELECT log1.*, COUNT(*) AS ConcurrentConnections
FROM tableLog AS log1
JOIN tableLog AS log2
AND log1.startDateTime <= log2.stopDateTime
AND log2.startDateTime <= log1.stopDateTime
GROUP BY log1.ID
) AS grp
GROUP BY MACDevice
警告:使用大型日志表,此查询可能非常慢。