このコードをMySQLで単純化するにはどうすればよいですか?mySQLのSQLを縮退
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
計算された日付の数は動的なので、
(大規模なデータベースにあまりにも効率的ではないかもしれません)最初の1のためにサブクエリを使用しています。そのクエリは最初から悪い考えです。 – Blixt