0

2行の違いが必要です

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 に答える