在 mysql 中我们可以使用之前的输出数据进行查询。IE。,
select IPAddress,Sum(L2FramesSent),convert((min(datetime) div 500)*500, datetime) + INTERVAL 5 minute as endOfInterval from databasename.tablename where datetime BETWEEN '2012-09-20 10:00:00' AND '2012-09-20 16:45:00' group by datetime div 500;
通过上面的查询我得到了
+-----------+-------------------+---------------------+
| IPAddress | Sum(L2FramesSent) | endOfInterval |
+-----------+-------------------+---------------------+
| moteid6 | 523791 | 2012-09-20 10:05:00 |
| moteid4 | 349555 | 2012-09-20 11:00:00 |
| moteid6 | 276358 | 2012-09-20 11:05:00 |
| moteid4 | 525457 | 2012-09-20 12:00:00 |
| moteid4 | 960010 | 2012-09-20 12:05:00 |
| moteid13 | 1263313 | 2012-09-20 12:10:00 |
| moteid12 | 1001343 | 2012-09-20 12:15:00 |
| moteid4 | 325904 | 2012-09-20 13:00:00 |
| moteid14 | 691390 | 2012-09-20 13:05:00 |
| moteid4 | 1028479 | 2012-09-20 15:40:00 |
| moteid12 | 1394286 | 2012-09-20 15:45:00 |
| moteid12 | 1336231 | 2012-09-20 15:50:00 |
| moteid6 | 263674 | 2012-09-20 15:55:00 |
+-----------+-------------------+---------------------+
现在我想要difference
两行之间是否有可能得到它如果我给这个:
select (b.Sum(L2FramesSent) - a.Sum(L2FramesSent)),convert((min(a.datetime) div 500)*500, datetime) + INTERVAL 5 minute as endOfInterval from tablename.databasename a,tablename.databasename b where a.datetime BETWEEN '2012-09-12 11:00:00' AND '2012-09-12 17:05:00' group by a.datetime div 500;
我收到错误 ERROR 1630 (42000): FUNCTION b.Sum does not exist
。检查参考手册中的“函数名称解析和解析”部分
表名和数据库名都相同。