我想存储查询的结果,然后将这些结果与下一组进行比较.可能的


I would like to store the results of a query, then compare those results to the next set. Possible?

//This is my query
SELECT bline_id, ROUND(Avg(flow),3) avg  
FROM   (SELECT id, bline_id, flow, date, CASE 
             WHEN @previous IS NULL 
               OR @previous = bline_id THEN @rownum := @rownum + 1 
             ELSE @rownum := 1 
           end rn, 
           @previous := bline_id 
    FROM   blf, 
           (SELECT @rownum := 0, 
                   @previous := NULL) t 
    WHERE bline_id > 0 and bline_id < 31
    ORDER  BY bline_id, 
              date DESC, 
              id) t 
  WHERE  rn < 11
  GROUP  BY bline_id

该查询取最近10条记录的平均值。我希望能够将这些结果保存回数据库,并将它们与添加新记录时的下一组10进行比较。

我想要的最终结果是能够判断平均值是否有+或- 2%的变化。这有道理吗?

您可以创建一个包含以下字段的表:

id, bline_id, avg, timestamp

每次添加一条记录时,将上面查询的结果插入到该表中。

您可以将此表中的最新记录与前一条记录进行比较。