By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
Records: 20 Duplicates: 0 Warnings: 0
@sql |
---|
SELECT s.user_id, MAX(IF(s.name = "bar", `value`,"")) AS bar,MAX(IF(s.name = "baz", `value`,"")) AS baz,MAX(IF(s.name = "foo", `value`,"")) AS foo,MAX(IF(s.name = "quux", `value`,"")) AS quux,MAX(IF(s.name = "waldo", `value`,"")) AS waldo FROM table1 s GROUP BY s.user_id ORDER BY s.user_id |
Statement prepared
user_id | bar | baz | foo | quux | waldo |
---|---|---|---|---|---|
10 | 15 | 390 | 40 | ENG | 1 |
13 | 15 | 0 | 20 | ENG | 1 |
15 | 1 | 420 | 5 | ENG | 1 |
16 | 15 | 0 | 5 | ENG | 1 |