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

Regarding to fetch the count thru a db2 query


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

Active User


Joined: 27 Feb 2008
Posts: 110
Location: india

PostPosted: Tue Feb 23, 2010 1:36 pm
Reply with quote

This is regarding to fetch the count thru a db2 query.

Table name : EMP_SCHOOL
lot of columns are there in the table.
I want to get the maximum number of admission in a day.
for ex: i have a field like EMP_ID, ADMISSION_DATE..

If a person gets admission, then he/she get the EMP_ID on that day.

So i want to retrieve the maximum number of count people have taken the admission on a perticular day..

or which date the maximum no. of people taken the admission and how many...

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

Active User


Joined: 31 May 2007
Posts: 171
Location: India

PostPosted: Tue Feb 23, 2010 2:21 pm
Reply with quote

Hello,
Select count(*) from EMP_SCHOOL
where ADMISSION_DATE = "02/23/201"
Back to top
View user's profile Send private message
Srihari Gonugunta

Active User


Joined: 14 Sep 2007
Posts: 295
Location: Singapore

PostPosted: Tue Feb 23, 2010 3:25 pm
Reply with quote

Subrat,
You can try the following queries.


Code:
SELECT A.ADMISSION_DATE, A.CNT
FROM
(SELECT ADMISSION_DATE,COUNT(*) AS CNT FROM EMP_SCHOOL
GROUP BY ADMISSION_DATE) A
WHERE A.CNT = (SELECT MAX(B.CNT) FROM
(SELECT ADMISSION_DATE,COUNT(*) AS CNT FROM EMP_SCHOOL
GROUP BY ADMISSION_DATE) B);


Code:
WITH EMPCTE(ADMISSION_DATE,CNT) AS
(SELECT ADMISSION_DATE,COUNT(*) AS CNT FROM EMP_SCHOOL
 GROUP BY ADMISSION_DATE)
SELECT ADMISSION_DATE,CNT FROM EMPCTE WHERE
CNT = (SELECT MAX(CNT) FROM EMPCTE);
Back to top
View user's profile Send private message
Srihari Gonugunta

Active User


Joined: 14 Sep 2007
Posts: 295
Location: Singapore

PostPosted: Tue Feb 23, 2010 7:38 pm
Reply with quote

Subrat,
You can also try the following.

Code:
SELECT ADMISSION_DATE,COUNT(*) AS CNT FROM EMP_SCHOOL
GROUP BY ADMISSION_DATE
ORDER BY 2 DESC
FETCH FIRST 1 ROWS ONLY;
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 To find whether record count are true... DFSORT/ICETOOL 6
No new posts RC query -Time column CA Products 3
No new posts Validating record count of a file is ... DFSORT/ICETOOL 13
No new posts Dynamically pass table name to a sele... DB2 2
Search our Forums:

Back to Top