SQL: Unpivot Data

Medium
SQL — Advanced SQL UNION ALL Unpivot
Transform columns back to rows.

Constraints

Write standard SQL (MySQL 8.0 compatible).

Examples

Example 1:
Input: name q1 q2 Ahmed 100 200
Output:
Example 2:
Input: name q1 q2 Ahmed 100 200
Output:

Hints

UNION ALL or UNPIVOT.
▲ Console

Install Talent Arabia

Get instant access to jobs and career tools on your device.