Ollivander’s Inventory in SQL | HackerRank Programming Solutions | HackerRank SQL Solutions

Hello Programmers/Coders, Today we are going to share solutions of Programming problems of HackerRank of Programming Language SQL. At Each Problem with Successful submission with all Test Cases Passed, you will get an score or marks. And after solving maximum problems, you will be getting stars. This will highlight your profile to the recruiters.

In this post, you will find the solution for Employee Salaries in SQL-HackerRank Problem. We are providing the correct and tested solutions of coding problems present on HackerRank. If you are not able to solve any problem, then you can take help from our Blog/website.

Use “Ctrl+F” To Find Any Questions Answer. & For Mobile User, You Just Need To Click On Three dots In Your Browser & You Will Get A “Find” Option There. Use These Option to Get Any Random Questions Answer.

Introduction To SQL

SQL stands for Structured Query Language. SQL is used to create, remove, alter the database and database objects in a database management system and to store, retrieve, update the data in a database. SQL is a standard language for creating, accessing, manipulating database management system. SQL works for all modern relational database management systems, like SQL Server, Oracle, MySQL, etc.

  • It is a standard language for Relational Database System. It enables a user to create, read, update and delete relational databases and tables.
  • All the RDBMS like MySQL, Informix, Oracle, MS Access and SQL Server use SQL as their standard database language.
  • SQL allows users to query the database in a number of ways, using English-like statements.

Link for the ProblemOllivander’s Inventory SQL – Hacker Rank Solution

Ollivander’s Inventory SQL – Hacker Rank Solution


Harry Potter and his friends are at Ollivander’s with Ron, finally replacing Charlie’s old broken wand.

Hermione decides the best way to choose is by determining the minimum number of gold galleons needed to buy each non-evil wand of high power and age. Write a query to print the idagecoins_needed, and power of the wands that Ron’s interested in, sorted in order of descending power. If more than one wand has same power, sort the result in order of descending age.

Input Format

The following tables contain data on the wands in Ollivander’s inventory:

  • Wands: The id is the id of the wand, code is the code of the wand, coins_needed is the total number of gold galleons needed to buy the wand, and power denotes the quality of the wand (the higher the power, the better the wand is). 1458538092 b2a8163a74 ScreenShot2016 03 08at12.13.39AM
  • Wands_Property: The code is the code of the wand, age is the age of the wand, and is_evil denotes whether the wand is good for the dark arts. If the value of is_evil is 0, it means that the wand is not evil. The mapping between code and age is one-one, meaning that if there are two pairs,  and , then  and .1458538221 18c4092b7d ScreenShot2016 03 08at12.13.53AM

Sample Input

Wands Table: 1458538559 51bf29644e ScreenShot2016 03 21at10.34.41AM Wands_Property Table: 1458538583 fd514566f9 ScreenShot2016 03 21at10.34.28AM

Sample Output

9 45 1647 10
12 17 9897 10
1 20 3688 8
15 40 6018 7
19 20 7651 6
11 40 7587 5
10 20 504 5
18 40 3312 3
20 17 5689 3
5 45 6020 2
14 40 5408 1
Ollivander’s Inventory SQL – Hacker Rank Solution
SELECT a.id, 
FROM   wands a 
   JOIN wands_property b 
     ON a.code = b.code 
WHERE  b.is_evil = 0 
    AND a.coins_needed = (SELECT Min(a1.coins_needed) 
    FROM   wands a1 
        JOIN wands_property b1 
          ON a1.code = b1.code 
    WHERE  b.age = b1.age 
        AND a.power = a1.power) 
ORDER  BY a.power DESC, 
          b.age DESC;

52 thoughts on “Ollivander’s Inventory in SQL | HackerRank Programming Solutions | HackerRank SQL Solutions”

  1. Yoᥙ have made some decent points there. I looked օn the net to find out more aЬout the
    issue and found most people will go aⅼong with your
    views on this ԝeb site.

  2. Whats Taking place i am new to this, I stumbled upon this I have found It positively helpful and it has aided me out loads. I hope to contribute & help other customers like its aided me. Good job.

  3. I have to point out my admiration for your generosity for persons who have the need for guidance on this field. Your personal dedication to getting the solution around had been extremely functional and has continuously enabled regular people much like me to achieve their desired goals. Your amazing useful publication indicates a lot a person like me and additionally to my office colleagues. Regards; from everyone of us.

  4. Thank you for any other informative site. Where else may just I am getting that kind of info written in such a perfect method? I’ve a venture that I’m just now running on, and I have been on the look out for such information.

  5. This is the proper blog for anybody who wants to find out about this topic. You realize a lot its virtually hard to argue with you (not that I really would need…HaHa). You positively put a new spin on a topic thats been written about for years. Great stuff, simply nice!

  6. Howdy! This is my 1st comment here so I just wanted to give a quick shout out and say I genuinely enjoy reading your blog posts. Can you suggest any other blogs/websites/forums that cover the same topics? Thanks a lot!

  7. I don’t even know how I stopped up right here, however I thought this submit was once great. I do not realize who you might be but definitely you’re going to a famous blogger should you aren’t already 😉 Cheers!


Leave a Comment

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker🙏.

Powered By
Best Wordpress Adblock Detecting Plugin | CHP Adblock