Quick question, I have the following table
+-------------+---------------------+
| total | o_date |
+-------------+---------------------+
Get Month And Year wise data from MySQL database:
SELECT MONTHNAME(o_date), YEAR(o_date), SUM(total)
FROM the_table
GROUP BY YEAR(date), MONTH(date)
SELECT SUM(total)
FROM table
GROUP BY MONTH(o_date)
This solution will give you the month name as a column of your resultset, followed by the total as required.
SELECT MONTHNAME(o_date), SUM(total)
FROM theTable
GROUP BY YEAR(o_date), MONTH(o_date)
SELECT year(FROM_UNIXTIME(created)) year, month(FROM_UNIXTIME(created)) month, sum(amount) total
FROM {my_table}
GROUP BY year, month
ORDER BY year, month;
Try Group BY
, like this:
select count(A_id) As Tid,Day(CrDate) from Ap Group By Day(CrDate)
select year(o_date), month(o_date), sum(total)
from table
group by year(o_date), month(o_date);