mysql pivot query results with GROUP BY

前端 未结 2 1921
我在风中等你
我在风中等你 2020-11-27 22:27

I have a table to data that I want to export to a CSV. Ideally, I\'d like to switch the rows and columns around, so that the data is grouped a little better.

To expl

2条回答
  •  迷失自我
    2020-11-27 22:46

    Just join the table to itself!

    SELECT dt1.data_timestamp, dt1.input_1, dt2.input_2
    FROM data_timestamp dt1
    JOIN data_timestamp dt2 
        on dt1.data_timestamp = dt2.data_timestamp 
        and dt2.input_1 is null
    WHERE dt1.input_2 is null;
    

    Note that this query assumes input_2's value are present for every input_1 value. If that's not that case, use LEFT JOIN or CROSS JOIN etc

提交回复
热议问题