MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Resultant table....

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
psridhar
Beginner


Joined: 16 May 2004
Posts: 68
Topics: 26

PostPosted: Tue Feb 01, 2005 10:26 am    Post subject: Resultant table.... Reply with quote

Can anybody help me in achieving the resultant table as follows.

My main table contains the columns as follows.

[code:1:181fa4cca1]
----------------------------------------------------------------------
Month Year Customer Id Fee Type Fee Amount
----------------------------------------------------------------------
12 2004 C1 AAAA 100.00
12 2004 C1 BBBB 70.00
12 2004 C2 AAAA 30.00
12 2004 C2 CCCC 50.00
12 2004 C3 AAAA 55.00
12 2004 C3 BBBB 75.00
01 2005 C2 AAAA 65.00
01 2005 C3 AAAA 45.00
01 2005 C3 BBBB 55.00
01 2005 C4 AAAA 25.00
01 2005 C4 CCCC 35.00
----------------------------------------------------------------------

Say the fee paid in 12-2004 as Previous Sum and in 01-2005 as Current Sum.

My resultant table should be as follows.

-------------------------------------------------------
Customer Id Current Sum Previous Sum
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Tue Feb 01, 2005 11:50 am    Post subject: Reply with quote

Psridhar,

What is the column definitions of Month, YR and amount fields?

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Tue Feb 01, 2005 1:32 pm    Post subject: Reply with quote

Psridhar,

Assuming that your column definitions for month and year are integers, the following query will give you the desired results.
Code:

SELECT A.CUST_ID                                                   
      ,SUM(A.PREV1)  CURR_SUM                                       
      ,SUM(A.PREV2)  PREV_SUM                                       
  FROM (SELECT CUST_ID                                             
              ,CASE WHEN MO = MONTH(CURRENT DATE) AND               
                         YR = YEAR(CURRENT DATE)                   
                    THEN FEE_AMT ELSE 0 END  CURR1                 
              ,CASE WHEN MO = MONTH(CURRENT DATE - 1 MONTH ) AND   
                         YR = YEAR(CURRENT DATE  - 1 MONTH)         
                    THEN FEE_AMT ELSE 0 END  PREV1                 
              ,CASE WHEN MO = MONTH(CURRENT DATE - 2 MONTH ) AND   
                         YR = YEAR(CURRENT DATE  - 2 MONTH)         
                    THEN FEE_AMT ELSE 0 END  PREV2                 
          FROM T1) A                                               
GROUP BY A.CUST_ID                                                 
;                                                                   


Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
psridhar
Beginner


Joined: 16 May 2004
Posts: 68
Topics: 26

PostPosted: Wed Feb 02, 2005 5:14 am    Post subject: Reply with quote

Hi Kolusu

Thank you very much..... With some slight modifications to your SQL, I could able to achieve my requirement. Thanks for the suggessions.

Thanks
Sridhar
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group