SQL组结果为" sequence"

时间:2015-03-01 18:03:50

标签: mysql sql date

我有一个数据库(MySQL),其表格如下:

列定义:

ID (pk , long , auto_increment) ,
raw_data (double) ,
numDevice (int) ,
numVar (int) ,
timemillis (long)  , 
date (timestamp) 

数据示例:

ID |RAW_DATA           |numDevice | numVar |TIMEMILLIS   |   TIMESTAMP
 01| 86.23775482177734 |    1     | 1      |1424180019706|2015-02-17 13:33:39
 02| 91.85794067382812 |    1     | 1      |1424180022857|2015-02-17 13:34:42
 03| 88.02635192871094 |    1     | 1      |1424180026008|2015-02-17 13:35:46
 04| 89.89857482910156 |    1     | 1      |1424180029159|2015-02-17 15:22:49
 05| 86.82943725585938 |    1     | 1      |1424180035460|2015-02-17 15:23:55
 06| 93.07737731933594 |    1     | 1      |1424180038613|2015-02-17 15:24:58
 07| 87.77403259277344 |    1     | 1      |1424180041764|2015-02-17 18:34:01
 08| 92.69800567626953 |    1     | 1      |1424180044915|2015-02-17 18:34:04
 09| 90.60401916503906 |    1     | 1      |1424180048067|2015-02-17 18:34:08
 10| 88.20098876953125 |    1     | 1      |1424180051218|2015-02-17 18:34:11

...........

我搜索一个查询,按照最后1分钟的间隔按日期对结果进行分组,例如,此查询应具有结果:

第1组:

 01| 86.23775482177734 |    1     | 1      |1424180019706|2015-02-17 13:33:39
 02| 91.85794067382812 |    1     | 1      |1424180022857|2015-02-17 13:34:42
 03| 88.02635192871094 |    1     | 1      |1424180026008|2015-02-17 13:35:46

第2组:

 04| 89.89857482910156 |    1     | 1      |1424180029159|2015-02-17 15:22:49
 05| 86.82943725585938 |    1     | 1      |1424180035460|2015-02-17 15:23:55
 06| 93.07737731933594 |    1     | 1      |1424180038613|2015-02-17 15:24:58

第3组

 07| 87.77403259277344 |    1     | 1      |1424180041764|2015-02-17 18:34:01
 08| 92.69800567626953 |    1     | 1      |1424180044915|2015-02-17 18:34:04
 09| 90.60401916503906 |    1     | 1      |1424180048067|2015-02-17 18:34:08
 10| 88.20098876953125 |    1     | 1      |1424180051218|2015-02-17 18:34:11

自从我在网上搜索没有成功已经两天了,欢迎任何帮助。谢谢

1 个答案:

答案 0 :(得分:0)

相反,请考虑每个“组”一行:

SELECT  CONCAT(MIN(id), '-', MAX(id)) AS id_range,
        SUM(RAW_DATA) AS sum_raw_data,
        CONCAT(MIN(TIMESTAMP), ' - ', RIGHT(MAX(TIMESTAMP), 8)) AS time_span
    FROM  tbl
    GROUP BY  LEFT(TIMESTAMP, 15);

那应该给你一些:

01-03   266.666666   2015-02-17 13:33:39 - 13:35:46
04-06   277.888888   ...