This topic is locked

Query: Retrieve Monthly totals from Date Col

4/16/2010 9:51:41 PM
PHPRunner General questions
N
nti author
  1. Table has two fields; Date and Deposits.
    Date Format: mm/dd/yyyy
    Table has 500+ records.
    In need of Query for pulling the "total sum" for each month in ONE QUERY.
    The below Query pulls the Total for the month of January.
    SELECT

    SUM(Deposits) AS January

    FROM Bus_Chk_Reg

    WHERE (Date =1)
    I'm hoping there is a simple method to pull the results for all 12 months!?
    All feedback appreciated. Thanks

J
Jane 4/23/2010

Hi,
to sum values based on the month use GROUP BY statement in the SQL query.

Here is a sample:

SELECT

month(`Date`) as `MonthName`,

SUM(Deposits) AS sumDeposits

FROM Bus_Chk_Reg

Group By month(`Date`)