LINUX.ORG.RU

История изменений

Исправление anonymus123, (текущая версия) :

Перевести время в таймстемп, посчитать сумму unpause, отнять cумму pause. u1-p1 + u2-p2 = u1+u2 - (p1+p2)

 select agent,time,event,sum(CASE WHEN event='UNPAUSE' THEN UNIX_TIMESTAMP(time) END) AS UNPAUSE, sum(CASE WHEN event='PAUSE' THEN UNIX_TIMESTAMP(time) END) AS PAUSE from queue_log where event like '%PAUSE' and date(time) > CURDATE()-INTERVAL 1 month and agent='2038';
+-------+----------------------------+-------+--------------------+--------------------+
| agent | time                       | event | UNPAUSE            | PAUSE              |
+-------+----------------------------+-------+--------------------+--------------------+
| 2038  | 2019-12-12 17:03:50.353069 | PAUSE | 11033993992.638348 | 12610308939.583187 |
+-------+----------------------------+-------+--------------------+--------------------+
1 row in set (0.01 sec)


 select agent,time,event,sum(CASE WHEN event='UNPAUSE' THEN UNIX_TIMESTAMP(time) END) - (sum(CASE WHEN event='PAUSE' THEN UNIX_TIMESTAMP(time) END)) DIFF from queue_log where event like '%PAUSE' and date(time) > CURDATE()-INTERVAL 1 month and agent='2038';
+-------+----------------------------+-------+--------------------+
| agent | time                       | event | DIFF               |
+-------+----------------------------+-------+--------------------+
| 2038  | 2019-12-12 17:03:50.353069 | PAUSE | -1576314946.944839 |
+-------+----------------------------+-------+--------------------+
1 row in set (0.00 sec)

что-то не то … )

Исходная версия anonymus123, :

 select agent,time,event,sum(CASE WHEN event='UNPAUSE' THEN UNIX_TIMESTAMP(time) END) AS UNPAUSE, sum(CASE WHEN event='PAUSE' THEN UNIX_TIMESTAMP(time) END) AS PAUSE from queue_log where event like '%PAUSE' and date(time) > CURDATE()-INTERVAL 1 month and agent='2038';
+-------+----------------------------+-------+--------------------+--------------------+
| agent | time                       | event | UNPAUSE            | PAUSE              |
+-------+----------------------------+-------+--------------------+--------------------+
| 2038  | 2019-12-12 17:03:50.353069 | PAUSE | 11033993992.638348 | 12610308939.583187 |
+-------+----------------------------+-------+--------------------+--------------------+
1 row in set (0.01 sec)


 select agent,time,event,sum(CASE WHEN event='UNPAUSE' THEN UNIX_TIMESTAMP(time) END) - (sum(CASE WHEN event='PAUSE' THEN UNIX_TIMESTAMP(time) END)) DIFF from queue_log where event like '%PAUSE' and date(time) > CURDATE()-INTERVAL 1 month and agent='2038';
+-------+----------------------------+-------+--------------------+
| agent | time                       | event | DIFF               |
+-------+----------------------------+-------+--------------------+
| 2038  | 2019-12-12 17:03:50.353069 | PAUSE | -1576314946.944839 |
+-------+----------------------------+-------+--------------------+
1 row in set (0.00 sec)

что-то не то … )