Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Need a query to count of distinct vehicle code

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Need a query to count of distinct vehicle code
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    Post subject:
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    Post subject: Re: Need a query to count of distinct vehicle code
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts UNIT=AFF for Easytrieve code gandikk JCL & VSAM 7 Wed Jul 12, 2017 11:42 pm
No new posts CICS Transaction attach count of supp... lind sh CICS 1 Wed Jun 21, 2017 1:33 pm
No new posts Need DB2 query to fetch previous row ! Chandan1993 DB2 10 Sat Jun 03, 2017 10:43 am
No new posts DB2 Program abending without giving a... rahulgarg14 DB2 7 Mon May 29, 2017 8:10 pm
No new posts Job failing with USER = 4093 REASON C... Pradeepa S ABENDS & Debugging 1 Wed May 17, 2017 3:35 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us