How to get SUM of Select Data according to Month and Year

I have following table in mysql database. My task was I need to get the sum of the paid_amount and the month and year.
See below Image

I used following sql command to get sum of the paid amount accourding to month and the year. See below result in the image.


SELECT 
        Sum(paid_amount)       AS paid_amount
        Year(`paid_time`)      AS paid_year,
        Monthname(`paid_time`) AS paid_month 
FROM   
    `customer_payment_table` 
WHERE  `paid` = 1 
GROUP  BY 
    Year(paid_time),
        Month(paid_time)  
Some are without date, That's why I got Null in first result statement. :)

0 comments:

Post a Comment

Ask anything about this Tutorial.