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

Maximum count grouped by a particular column


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
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
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: 1281
Location: Belgium

PostPosted: Thu Nov 18, 2010 12:48 pm
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts To get the count of rows for every 1 ... DB2 3
No new posts To find whether record count are true... DFSORT/ICETOOL 6
No new posts How to load to DB2 with column level ... DB2 6
No new posts RC query -Time column CA Products 3
Search our Forums:

Back to Top