suppose I have the following data, how can I transpose the data with MYSQL so that the output looks like the following table?
WITH mydata
AS (SELECT '123' AS id,
1 AS he_has_logo,
0 AS i_have_logo,
1 AS he_has_image,
1 AS i_have_image)
SELECT *
FROM mydata
variable he i
has_logo 1 1
has_image 1 0
CodePudding user response:
Use UNION
SELECT 'has_logo' AS variable, he_has_logo AS he, i_have_logo AS i
FROM mydata
UNION ALL
SELECT 'has_image' AS variable, he_has_image AS he, i_have_image AS i
FROM mydata