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
 

 

Count of unique rows

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
murugan_mf

Active User


Joined: 31 Jan 2008
Posts: 148
Location: Chennai, India

PostPosted: Tue Sep 30, 2008 9:08 am    Post subject: Count of unique rows
Reply with quote

Hi all,
I have table with the following colomns.
x char(10)
y char(15)

Sample rows:
x y
-- ---
12 abc
13 qwe
13 qwe
19 xyz
21 xyz
21 xyz
o/p--4

Here I want the count of unique rows of both x and y to gether.
Can any one suggest me the query?
Back to top
View user's profile Send private message

birdy K

New User


Joined: 05 Mar 2008
Posts: 72
Location: chennai

PostPosted: Tue Sep 30, 2008 10:55 am    Post subject:
Reply with quote

Hi,

Select x,y,count(*) from table a where not exists(select ' ' from table b where a.x=b.x and a.y=b.y having count(*) > 1) group by x,y.

But I have a doubt Why you need the count. Anyway the unique rows count will be 1. Isnt it?. Corrections are welcome.
Back to top
View user's profile Send private message
birdy K

New User


Joined: 05 Mar 2008
Posts: 72
Location: chennai

PostPosted: Tue Sep 30, 2008 11:48 am    Post subject:
Reply with quote

The correction in my query.
Code:

Select count(*) from table a where not exists(select ' ' from table b where a.x=b.x and a.y=b.y having count(*) > 1).

Now only understood that you need the total count of unique rows.
Back to top
View user's profile Send private message
Sachinincsc

New User


Joined: 01 Oct 2008
Posts: 11
Location: Philadelphia, USA

PostPosted: Wed Oct 01, 2008 7:39 pm    Post subject:
Reply with quote

SELECT COUNT(*) FROM ( SELECT DISTINCT...)

Try this..
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 How to generate a new unique Input fi... for1ranjith CLIST & REXX 11 Sat Jul 01, 2017 12:09 pm
No new posts CICS Transaction attach count of supp... lind sh CICS 1 Wed Jun 21, 2017 1:33 pm
No new posts compare 2 rows within the same file ram_vizag SYNCSORT 7 Wed Jun 14, 2017 12:34 am
No new posts Check if any Detail records and extra... V S Amarendra Reddy SYNCSORT 19 Mon May 08, 2017 8:54 pm
This topic is locked: you cannot edit posts or make replies. Merge two files and update Trailer re... Yashashri JCL & VSAM 1 Thu May 04, 2017 12:54 pm


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