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
 

 

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: 72
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 Join in SQL Query vickey_dw DB2 2 Tue Jan 17, 2017 12:15 am
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm


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