Oluwafunmilayo C. Sofuwa
3 min readMay 27, 2019

SQL: The Hackerrank Challenge

Hello everyone!!!

New Month, New Challenges!! The project for this month from the GitGirl School of Data that I attend is putting our knowledge about SQL to practice through the HackerRank SQL challenge. Before I go on to discussing the challenge, we had to study some advanced syntax and functions in SQL. These include but are not limited to case when, advanced queries such as correlated and nested sub-queries, window functions and so on. Now, in order to get a better understanding to these advanced syntax and functions in SQL, it is paramount that you have a beginner’s knowledge in SQL. That being said, there are sites and online programs that you can learn this from including Youtube, DataCamp as well as GitGirl School of Data among other options.

I’m going to let you in on a little secret and that is, I did not really understand what exactly I was studying this month. I had a ton of material to cover and it was really challenging for me and if it is the same way for you, that’s okay. Just remember, you have to keep practicing. I sometimes go back to the beginning again which is what I’m currently doing to better understand what I am trying to study. That being said, I had to start working on the HackerRank SQL challenges knowing that I would learn new things along the way. The easy challenges were relatively easy to solve but the medium challenges were kind of a hard nut to crack. Sometimes, I had to go through the discussions for such challenges to better understand how to go about solving the challenges. There were certain new terms and lessons I learnt along the way such as:

CEIL: This is used to obtain the smallest integer which is greater than or equal to a numeric expression. It helps you round up decimal numbers.

FLOOR: This is the opposite of the ‘CEIL’ function. This helps you round down decimal numbers.

HAVING: This works in the same way as the ‘WHERE’ clause with the exception that it work with aggregate values which the ‘WHERE’ clause cannot carry out.

Lesson 1: When writing queries, especially sub-queries, you have to be careful about your indentation.

Lesson 2: You have to use the right syntax else it could affect your whole query.

Lesson 3: Always spell-check your queries.

I’m going to share 2 challenges (1 easy and 1 medium challenge) along with my solution. Note that there is never just one way to go about solving these challenges.

PROBLEM 1
SOLUTION 1
PROBLEM 2
SOLUTION 2

I hope you enjoyed this post and don’t forget practice is key!!

Until next time, happy learning!