Get individual total of each month orders for last 6 months

hi all

i have order_table and in it i have “order_total” field
which holds value of sum total of each order.

I want to get sum total of previous 6 months orders processed on monthly basis

january = 21000
feb = 30050
march = 25000
april = 45000
may = 66000
june = 71000

i tried the below code

$qry = "select sum(order_total) from order_table where order_date >= DATE_FORMAT(CURDATE(), '%Y-%m-01') - INTERVAL 6 MONTH and payment_status='PAID'";
    $result = mysql_query($qry);
    while($row = mysql_fetch_array($result))
    {
    $total = $row[0];
    echo $total;
    }

This above code gives me combined total of all months in one single value.

But i want different 6 values of total of each month.

how can i get 6 different monthly total values like this below

january = 21000
feb = 30050
march = 25000
april = 45000
may = 66000
june = 71000

vineet

Use the function extract to get the month from order_date and add this to the select list. The add a group by clause using the the month value.

thanks.
working now

vineet

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.