从MySQL查询制作清单

时间:2018-09-27 07:36:08

标签: mysql sql

我有一些原始数据,如图片1

可以进行查询并显示如下图2所示的数据

我不知道如何进行查询以使结果显示在第2号图片中,有人可以帮助我解决这个问题吗?

图片1

enter image description here

图片2

enter image description here

谢谢

1 个答案:

答案 0 :(得分:0)

用例何时

select user, max(case when data='on' then date end )as start,
            max( case when data ='off' then date end) as end
         from t group by user