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.                                  ...