IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Need a query to count of distinct vehicle code


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
noorkh

New User


Joined: 06 Mar 2006
Posts: 76
Location: Chennai

PostPosted: Wed Jan 10, 2007 2:17 pm
Reply with quote

Hi,

These are my requirement.

I have one table called TVEHICLE.

There are 2 columns Policy no, Vehicle code.

I want to know the count of distinct vehicle code for the same policy no.

For eg:

Policy no Vehicle code
1234 45
1234 46
1234 47
1234 47
1236 48
1236 49

So the output should be

Policy no count
1234 2 for 45,46 ( 47 should not be considered as it is duplicate)
1235 2

Can anyone of you give me idea how to query for this?

Thanks Noor
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Wed Jan 10, 2007 3:21 pm
Reply with quote

here is your query

SELECT POLICY_NO,COUNT(*) FROM SESSION.POLICY
WHERE VEH_NO NOT IN(SELECT VEH_NO FROM SESSION.POLICY
GROUP BY VEH_NO HAVING COUNT(*) > 1) GROUP BY POLICY_NO;
Back to top
View user's profile Send private message
noorkh

New User


Joined: 06 Mar 2006
Posts: 76
Location: Chennai

PostPosted: Thu Jan 11, 2007 1:06 pm
Reply with quote

Thanks
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts To get the count of rows for every 1 ... DB2 3
No new posts run rexx code with jcl CLIST & REXX 15
No new posts Compile rexx code with jcl CLIST & REXX 6
No new posts To find whether record count are true... DFSORT/ICETOOL 6
No new posts RC query -Time column CA Products 3
Search our Forums:

Back to Top