mysql - Getting formatted and sorted data from SQL -
i data sql graph. instead of getting data , sorting in php solve using sql.
the dates should grouped day , platform should counted , sorted ios , android.
bonus: if can sort platform values, rather given values, better.
here data presented in sql:
date |platform --------------------+---------- 2014-04-22 11:15:55 |ios 2014-04-22 12:15:55 |android 2014-04-22 13:15:55 |ios 2014-04-23 11:15:55 |ios 2014-04-23 12:15:55 |android 2014-04-23 13:15:55 |android
desired output:
date |ios |android ------------+-------+----- 2014-04-22 |2 |1 2014-04-23 |1 |2
select `date`, sum(`ios`) `ios`, sum(`android`) `android` (select date(`date`) `date`, case when `platform`='ios' 1 else 0 end `ios`, case when `platform`='android' 1 else 0 end `android` demo) t group `date`
Comments
Post a Comment