我们可以使用以前的查询输出进行查询

时间:2012-09-25 07:50:11

标签: mysql

在mysql中我们可以使用以前的输出数据进行查询。 即,

 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。检查参考手册中的“功能名称解析和解决方案”部分

tablename和databasename都是相同的。

1 个答案:

答案 0 :(得分:0)

错误在于:

select (b.Sum(L2FramesSent) - a.Sum(L2FramesSent))

select (Sum(b.L2FramesSent) - Sum(b.L2FramesSent))

代替

a和b是表的别名,sum是(通常可用)函数。