0

我需要两行的差异

SELECT ( b.l2framessent - a.l2framessent ), 
       CONVERT((Min(a.datetime) DIV 500)*500, datetime) 
       + INTERVAL 5 minute AS endOfInterval 
FROM   databasename.tablename a, 
       databasename.tablename b 
WHERE  a.ipaddress = 'moteid6' 
       AND b.ipaddress = 'moteid6' 
       AND a.datetime BETWEEN '2012-09-25 15:45:00' AND '2012-09-25 18:45:00' 
GROUP  BY a.datetime DIV 500;

这两行都来自同一个表、数据库和同一列

我得到消极和不相关的价值观

如何获得正确的值

select datetime, l2framessent 
from 6panview.Statistics3 
where ipaddress = 'moteid6' 
    AND datetime BETWEEN '2012-09-25 15:45:00' AND '2012-09-25 18:50:00';

+---------------------+--------------+
| datetime            | l2framessent |
+---------------------+--------------+
| 2012-09-25 17:45:56 |  25 |
| 2012-09-25 17:50:35 |  56 |
| 2012-09-25 17:55:15 |  87 |
| 2012-09-25 17:59:54 | 117 |
| 2012-09-25 18:04:33 | 148 |
| 2012-09-25 18:09:13 | 178 |
| 2012-09-25 18:13:52 | 208 |
| 2012-09-25 18:18:31 | 238 |
| 2012-09-25 18:23:10 | 269 |
| 2012-09-25 18:39:43 | 372 |
| 2012-09-25 18:44:23 | 402 |
| 2012-09-25 18:49:02 | 432 |
+---------------------+-----+
4

2 回答 2

0

尝试这个。不确定,但如果可行的话,祝你好运:

AND a.datetime BETWEEN TO_SECONDS('2012-09-25 15:45:00') AND TO_SECONDS('2012-09-25 18:45:00')
于 2012-09-26T07:03:14.073 回答
0

这是一个有效的查询。你一开始是对的,除以 500,我没有意识到 MySQL 如何将日期时间转换为数字。

SELECT ( b.l2framessent - a.l2framessent ), 
       CONVERT(endOfInterval*500, DATETIME) endOfInterval
FROM   (SELECT datetime DIV 500 startOfInterval,
               l2framessent
        FROM tablename,
             (SELECT MIN(datetime) mindate
              FROM tablename
              WHERE ipaddress = 'moteid6'
                    AND datetime BETWEEN '2012-09-25 15:45:00' AND '2012-09-25 18:45:00'
              GROUP BY datetime DIV 500) b
        WHERE ipaddress = 'moteid6'
              AND datetime = mindate
       ) a, 
       (SELECT datetime DIV 500 endOfInterval,
               l2framessent
        FROM tablename,
             (SELECT MIN(datetime) mindate
              FROM tablename
              WHERE ipaddress = 'moteid6'
                    AND datetime BETWEEN '2012-09-25 15:45:00' AND '2012-09-25 18:45:00'
              GROUP BY datetime DIV 500) b
        WHERE ipaddress = 'moteid6'
              AND datetime = mindate
       ) b
WHERE endOfInterval = startOfInterval + 1

小提琴

于 2012-09-26T09:17:39.477 回答