Results 1 to 2 of 2
  1. #1
    Join Date
    May 2002
    Posts
    1

    Unanswered: SQL QUERY for Month wise group

    Hello Friends,

    How to group by month wise in T-SQL ?

    I have the data like

    BuyerID Amount OrderDate
    =======================
    (dd/mm/yyyy)

    1 100 10/10/2002
    1 200 09/09/2002
    2 100 08/08/2002
    3 50 07/07/2002
    3 75 07/05/2002
    4 100 05/05/2002
    1 75 06/06/2002
    1 150 07/07/2002
    5 50 01/01/2002
    5 75 02/02/2002
    1 50 03/03/2002
    2 50 04/04/2002
    2 50 05/05/2002
    1 100 09/10/2002
    2 50 10/04/2002


    My output like
    ==========

    ID Amount Month
    ~~~~~~~~~~~~~~~~~~
    1 200 OCT
    1 200 SEP
    1 50 MAR
    1 75 JUN
    1 150 JULY


    2 100 Aug
    2 100 APR
    2 50 MAY

    3 75 MAY
    3 50 JULY


    4 100 MAY

    5 50 JAN
    5 75 FEB


    Thanks & Regards

    Raju

  2. #2
    Join Date
    Jan 2002
    Posts
    12
    try this out.....

    SELECT ID, SUM(AMOUNT) AMOUNT,
    CASE MONTH(DATESTAMP)
    WHEN 1 THEN 'JAN'
    WHEN 2 THEN 'FEB'
    WHEN 3 THEN 'MAR'
    WHEN 4 THEN 'APR'
    WHEN 5 THEN 'MAY'
    WHEN 6 THEN 'JUN'
    WHEN 7 THEN 'JUL'
    WHEN 8 THEN 'AUG'
    WHEN 9 THEN 'SEP'
    WHEN 10 THEN 'OCT'
    WHEN 11 THEN 'NOV'
    WHEN 12 THEN 'DEC'
    END MONTHNAME
    FROM MONTH_GROUP
    GROUP BY ID, MONTH(DATESTAMP)
    ORDER BY ID, MONTH(DATESTAMP)
    NivasKhan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •