php - Group by month in the date field (string) -
a table string field date beingness stored (don't suggest me alter field type. cause hazard).
+--+----------+------+ |id|date |amount| +--+----------+------+ |1 |23-03-2014|5000 | +--+----------+------+ |2 |25-03-2014|3000 | +--+----------+------+ |3 |21-04-2014|3000 | +--+----------+------+ |4 |25-04-2014|4000 | +--+----------+------+
i want write model function homecoming sum of amount grouped month table. how should it? show output like
03 - 8000 04 - 7000
select month(date_field) mon, sum(amount) total table_name grouping month(date_field);
update:
select substr(date_field,6,2) mon, sum(amount) total table_name grouping mon;
php codeigniter activerecord
No comments:
Post a Comment