How can I simplify this code in MySQL?
SELECT name,
MAX(IF(to_days(thedate) - to_days('2009-06-13') = 0, price, '')) AS date1,
MAX(IF(to_days(thedate) - to_days('2009-06-13') = 1, price, '')) AS date2,
MAX(IF(to_days(thedate) - to_days('2009-06-13') = 2, price, '')) AS date3,
MAX(IF(to_days(thedate) - to_days('2009-06-13') = 3, price, '')) AS date4,
MAX(IF(to_days(thedate) - to_days('2009-06-13') = 4, price, '')) AS date5,
MAX(IF(to_days(thedate) - to_days('2009-06-13') = 5, price, '')) AS date6,
MAX(IF(to_days(thedate) - to_days('2009-06-13') = 6, price, '')) AS date7,
AVG(price),SUM(price)
FROM `personals`
WHERE personal_id = '1234'
GROUP BY name
So that the number of dates calculated are dynamic?