Results 1 to 2 of 2

Thread: SQL Query

  1. #1
    Join Date
    Jun 2008
    Posts
    6

    Unanswered: SQL Query

    Here is the sample data

    memno|acct_num|routno|enrolldt|totalpaid|rpt_date
    100|2222|3245|2/2/2002|10|Mar
    120|4444|5678|3/2/2003|2|April
    543|6666|7676|4/4/2005|20|May
    999|8888|6900|6/7/2004|40|June



    I need the data in the format below

    memno|acct_num|routno|enrolldt|Mar|April|May|June
    100|2222|3245|2/2/2002|10|0|0|0
    120|4444|5678|3/2/2003|0|2|0|0
    543|6666|7676|4/4/2005|0|0|20|0
    999|8888|6900|6/7/2004|0|0|0|40

    I have never used decode. Any syggestions willl be helpful

    Thanks in advance for your help.

  2. #2
    Join Date
    Sep 2007
    Posts
    2
    Hi,

    Here u just write smaple data not the exact query .
    U can use Case statement in ur Query & I think below query some help u:-

    Select memno,acct_num,routno,enrolldt,
    sum(case when date(rpt_date) between "2008-03-01" and "2008-03-31" then totalpaid else 0 end) MAR,
    sum(case when date(rpt_date) between "2008-04-01" and "2008-04-30" then totalpaid else 0 end) APR,
    sum(case when date(rpt_date) between "2008-05-01" and "2008-05-31" then totalpaid else 0 end) MAY,
    sum(case when date rpt_date) between "2008-06-01" and "2008-06-30" then totalpaid else 0 end) JUN
    From Table_name

    Regard's

    Saurabh Goyal
    http://webexpert.wordpress.com

Posting Permissions

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