shyam rajpurohit shyam rajpurohit - 7 months ago 11
SQL Question

disply two rows from single row

This is the given table:

enter image description here

I need to get this data without creating temporary table based on the above table:

enter image description here

We can't use temporary table. I need to display the data with sql query only.

Answer

You can use UNION ALL to unpivot your table:

SELECT
    company,
    'No' AS val,
    impression AS data
FROM tbl
UNION ALL
SELECT
    company,
    'Yes' AS val,
    clicks - impression AS data
FROM tbl
ORDER BY company, val
Comments