If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Informix > SQL Query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-11-08, 22:04
jc2638 jc2638 is offline
Registered User
 
Join Date: Jun 2008
Posts: 6
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.
Reply With Quote
  #2 (permalink)  
Old 07-04-08, 03:20
sggoyal sggoyal is offline
Registered User
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On