Solving SQL Query | Rows to Column in SQL

In this video, we will solve an SQL Query where we will need to transform data from rows to column.

We can transform data from rows to column in SQL using PIVOT operator but not all RDBMS supports PIVOT. Microsoft SQL Server and Oracle supports PIVOT operator, whereas in PostgreSQL, we can transform rows to column using CROSSTAB function. Similarly in MySQL database, rows to column transformation can be done using the CASE statement.

Hence in this video, we shall first look at the SQL query problem statement. We understand the input data and also understand the expected output. After this we shall write SQL query to solve this problem using PIVOT in Microsoft SQL Server and in Oracle.

We shall then solve the same problem in PostgreSQL database using CROSSTAB function. Finally we shall also solve this query in MySQL database using the CASE statement.

All the datasets, scripts and SQL queries used in this video can be downloaded from below:

Watch the YouTube video

Previous
Previous

REAL SQL Interview Query | Complex SQL Interview Query and Solution

Next
Next

Solving 3 tricky SQL Interview Queries