title: Comparing day and week prices and getting cheapest
body: <p>I'm trying to get the lowest price of an object. Problem is there can be daily and weekly prices. So when searching for the cheapest price i have to multiply the day price time 7 and compare to the week price to get the cheapest.
  It can also happen that an object has week prices only or day prices only (or no prices at all).</p>
  
  <p>BTW: It has to be such a subselect query, cause i have some more WHERE queries following later.</p>
  
  <pre><code>Pricetable
  id  price   type    oid
  1   10      d       1
  2   12      d       2
  3   70      w       1
  4   80      w       2
  
  Objects
  id  name
  1   house1
  2   house2
  </code></pre>
  
  <p>This is what i'm using but its not working correctly. When the day price*7 is bigger that the week price it still gives me the day price.</p>
  
  <pre><code>SELECT p.oid, p.price, p.id, p.type FROM Pricetable p INNER JOIN (    
  SELECT oid, MIN(IF(type="w",price, price*7)) AS price, id, type
      FROM Pricetable     
      GROUP BY oid 
  ) p2 ON p.oid = p2.oid AND p.id= p2.id
  </code></pre>