1

How to transpose by grouping the column


time   tag     value

10     abc     67
11     abc     68
12     abc     65
10     cdf     23
11     cdf     24
12     cdf     25

to


time   abc     cdf
 
10     67      23
11     68      24
12     65      25
Soz
  • 63
  • 1
  • 11
  • 1
    What's your question? If your question is how to do a pivot table in MySQL... You can't really. You'll either have to do it in your application logic or get a better RDMS. – Jacobm001 Aug 18 '17 at 15:42
  • @Jacobm001 You really can. Although I agree that's it's not a great idea. – Strawberry Aug 18 '17 at 15:46

1 Answers1

0

This is a simple pivot query like this:

SELECT time
       SUM(IF(tag='abc',value,NULL)) AS abc,
       SUM(IF(tag='cdf',value,NULL)) AS cdf    
FROM yourTable
GROUP BY time

I hope to be helpful for you :)

Ali Adlavaran
  • 3,697
  • 2
  • 23
  • 47