Skip to content

HackerRank practice exercise for Pivoting in MySQL

nborbas/SQL_Pivoting_Practice_HackerRank

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

Pivoting with MySQL - HackerRank Exercise

Check out the page of HackerRank! They have really good and free practice exercises for SQL.
Check my solution under solution.sql file!

Exercise

Pivot the occupation column in occupations so that each Name is sorted alphabetically and displayed underneath its corresponding Occupation. The output column headers should be doctor, professor, singer, and actor, respectively.

Note: Print NULL when there are no more names corresponding to an occupation.

Input Format

The OCCUPATIONS table is described as follows:
image

Occupation will only contain one of the following values: Doctor, Professor, Singer or Actor.

Sample Input

image

Sample Output

image

Explanation

The first column is an alphabetically ordered list of Doctor names.
The second column is an alphabetically ordered list of Professor names.
The third column is an alphabetically ordered list of Singer names.
The fourth column is an alphabetically ordered list of Actor names.
The empty cell data for columns with less than the maximum number of names per occupation (in this case, the Professor and Actor columns) are filled with NULL values.

About

HackerRank practice exercise for Pivoting in MySQL

Resources

Stars

Watchers

Forks

Languages