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 

How to do multiple counts and compare in a single query?.

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


Joined: 19 Jul 2006
Posts: 32
Topics: 15

PostPosted: Wed Aug 09, 2006 12:48 pm    Post subject: How to do multiple counts and compare in a single query?. Reply with quote

Hi all,

This is my first post in MVSFORUMS and I am the silent reader of this forum for the past one month. This forum is great and informative!!.

Okay...My question is..let us assume that we have a table called policy_detail

This table has 3 fields....they are policy_no, policy_seq_no & trans_type.

The data in the table may be:
Code:

Policy_no  Policy_seq_no    Trans_type
12345       0               NBIS
12345       0               PCNM
12345       0               AUDF
12345       0               AUDR
12345       0               AUDV

In the above table, policy_no and policy_seq_no is the key. What I need to do is :

Count 1 : I need to find the count of AUDF+AUDR
Count 2 : I need to find the count of AUDV

If count1 = count2, then this query should return "True" or "Y"
Else this query should return "False" or "N".

I know I can handle this condition using two or more queries. But Is there a way I can get the result in a single query.

Thanks,
srini
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: Wed Aug 09, 2006 1:19 pm    Post subject: Reply with quote

spalanis,

try this

Code:

SELECT CASE WHEN SUM(CASE WHEN TRANS_TYPE = 'AUDF'       
                            OR TRANS_TYPE = 'AUDR'       
                          THEN INT(1) ELSE INT(0) END) = 
                 SUM(CASE WHEN TRANS_TYPE = 'AUDV'       
                          THEN INT(1) ELSE INT(0) END)   
            THEN CHAR('TRUE')                             
            ELSE CHAR('FALSE') END                       
  FROM TABLE ;                                               


btw there is already a similar question which discussed along with detailed explanation

http://www.mvsforums.com/helpboards/viewtopic.php?t=6589

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
spalanis
Beginner


Joined: 19 Jul 2006
Posts: 32
Topics: 15

PostPosted: Wed Aug 09, 2006 3:35 pm    Post subject: Reply with quote

Already so many of them said "you are great" I simply do not want to repeaty that Again Mr. Green

Anyway...I like your senthamizh name "Kolusu"
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