In mysql can we query by using the previous output data . 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;
By the above query I got
+-----------+-------------------+---------------------+
| 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 |
+-----------+-------------------+---------------------+
Now I want the difference
between two rows
Is it possible to get it
If I give this:
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;
I am getting error ERROR 1630 (42000): FUNCTION b.Sum does not exist
. Check the 'Function Name Parsing and Resolution' section in the Reference Manual
Both the tablename and databasename are the same.