Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Regarding to fetch the count thru a db2 query

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

New User


Joined: 27 Feb 2008
Posts: 82
Location: india

PostPosted: Tue Feb 23, 2010 1:36 pm    Post subject: Regarding to fetch the count thru a db2 query
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    Post subject: Reply to: db2 count
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    Post subject:
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    Post subject:
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    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 write Rexx program to size and... sreejeshcs CLIST & REXX 14 Thu Oct 12, 2017 7:26 am
No new posts HEX value search in a DB2 query maxsubrat DB2 2 Wed Oct 04, 2017 3:04 pm
No new posts Fetch Previous month & year in MM... girishb2 DFSORT/ICETOOL 3 Thu Sep 21, 2017 9:54 pm
No new posts Create procedure issues -628 when add... chandraBE DB2 1 Mon Sep 18, 2017 12:16 pm
No new posts column with count of rows within dist... ronald wouterson DB2 4 Sun Sep 17, 2017 9:48 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us