Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Transpose data in Mysql

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

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading