Skip to main content

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.



Comments

Popular posts from this blog

CodeSignal - Almost Strictly Increasing Sequence

I came across an interesting question in Code Signal.   "Given a sequence of integers as an array, determine whether it is possible to obtain a strictly increasing sequence by removing no more than one element from the array."                                                                                                         It is strictly increasing if every element in the array is greater than its successor.     For a strictly increasing sequence we can check for each element whether it is greater than the next. In that case we can come to a conclusion that this sequence is not strictl...

Deep Learning (Goodfellow et al) - Chapter 3 review

 After a long time starting my review with the third chapter!    This chapter jots down all necessary concepts of Probability and Information theory in regards to  the future scope of the book. While probability theory is introduced as a mathematical framework for representing uncertain statements, the information theory is introduced as the quantifying concept for the uncertainty. For deeper understanding, an additional resources would be good to consult like Jaynes(2003).      Truly computer science does not require the study of uncertainty until the machines start to learn from data. Because data and learning processes have uncertainty. The authors describe about the source of uncertainty.  There are three possible sources of uncertainty: - Inherent stochasticity in the system. - Incomplete Observability. - Incomplete Modeling.                                  ...

Deep Learning (Goodfellow et al) Book Review

    I bought a Deep Learning textbook this week! Deep Learning by Ian Goodfellow, Yoshua Bengio and Aaron Courville.     I bought it after a very thorough research on the contents and previous reviews. And actually it is a good choice. This book has developed to be one of the fundamental textbooks of Deep learning and is the latest of them.        I am excited about the book when i started reading it. But i feel reading is very lonely, i want to say what is actually exciting. I want to help some one who wants to know what the book is about. So i thought of writing a chapter wise review of the book. I plan to release review of each chapter on Fridays starting today(31/01/2019). I will keep updating this post with the links to the review of the chapter. This is my first experience in technical book review and i am hoping to do my best.   Chapter No Name Link Published/Scheduled Date 1 Introduction https:...