Skip to main content

Posts

Showing posts from December, 2019

Pivoting a SQL table

I came across an exciting question at Hacker Rank it was about pivoting a table in SQL. I here chose MySQL. The table had two columns of name and occupation. Problem: https://www.hackerrank.com/challenges/occupations/problem Solution: It would have been better to use Outer join. But since Outer join is not available with MySQL, i chose left join. Column with maximum values was chosen.I left joined the second maximum column to the first. Then left joined third max with them and so on. But while on final selection the columns were selected in the order as asked in the question from the joined table.