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
 

 

Maximum count grouped by a particular column

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

New User


Joined: 22 Sep 2008
Posts: 49
Location: Chennai,Tamilnadu

PostPosted: Thu Nov 18, 2010 11:41 am    Post subject: Maximum count grouped by a particular column
Reply with quote

Hi,

I want the maximum no of rows possible grouped by a particular column.

Code:


SELECT COUNT(*) FROM <Table A>
GROUP BY A.Column1

 


If the above query returns 1,2,3 I need the answer as 3.

ie I need

Code:

max(SELECT COUNT(*) FROM <Table A>
GROUP BY A.Column1).



Can it be achieved in SQL ?
Back to top
View user's profile Send private message

GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1278
Location: Belgium

PostPosted: Thu Nov 18, 2010 12:48 pm    Post subject:
Reply with quote

Code:
SELECT a.column1,COUNT(*) FROM <Table A>
GROUP BY A.Column1
order by 2 Desc
Fetch first 1 row only
Back to top
View user's profile Send private message
lokeshwar_manoharan

New User


Joined: 22 Sep 2008
Posts: 49
Location: Chennai,Tamilnadu

PostPosted: Thu Nov 18, 2010 2:59 pm    Post subject:
Reply with quote

Thanks.. it worked..!!
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 DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts SQZ pipe delimited file with 1 column... Rick Silvers DFSORT/ICETOOL 2 Sun Nov 06, 2016 8:11 pm
No new posts abend sort based on count records in ... anatol DFSORT/ICETOOL 5 Mon Oct 17, 2016 10:10 pm
This topic is locked: you cannot edit posts or make replies. Checking wether a string starts from ... sundaram.naveen CLIST & REXX 9 Thu Oct 06, 2016 11:56 am
No new posts Get Record count in summary record fo... Atul Banke DFSORT/ICETOOL 21 Fri Sep 23, 2016 4:17 pm


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