mysql选择2天前的行并根据日期列将其转换为列

时间:2017-10-20 06:38:02

标签: mysql

我有一些如下数据。

date                   metric  value
2011-05-18 09:17:25     m1        10
2011-05-18 09:17:25     m2        10
2011-05-17 09:17:25     m1        30
2011-05-17 09:17:25     m2        40
2011-05-16 09:17:25     m1        50
2011-05-16 09:17:25     m2        60
2011-05-15 09:17:25     m1        40
2011-05-15 09:17:25     m2        30
lost of more...

我想将两天前的行合并到列中,如下所示。

 date                    m1  m2   offsetdays  offset_date           m1    m2   
 2011-05-18 09:17:25     10  10       2       2011-05-16 09:17:25     50    60         
 2011-05-17 09:17:25     30  40       2       2011-05-15 09:17:25     40    30 

0 个答案:

没有答案