title: Group by and minimum aggregator (with join) in sql
body: <p>I am trying to teach my sql and am doing the hackerrank practice questions. I came across the Olivander's Inventory question, which says the following: 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 id, age, coins_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. <a href="https://www.hackerrank.com/challenges/harry-potter-and-wands/problem" rel="nofollow noreferrer">Here </a>is the link for more details. It is unhappy with my solution, and I think it is particularly something to do with the group by. What is wrong with what I have done and how do I fix it? Can I same small modifications to make it correct (i.e. still using the group by clause)?</p>
  
  <p>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 id, age, coins_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.</p>
  
  <pre><code>select w.id, wp.age, min(w.coins_needed), w.power
  from wands as w, wands_property as wp
  where w.code = wp.code and wp.is_evil = 0
  group by w.power, wp.age
  order by w.power desc, wp.age desc; 
  </code></pre>
  
  <p>I would appreciate suggestions! Thanks!</p>