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

Cursor required or not to get only the counts


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

New User


Joined: 19 Apr 2006
Posts: 22
Location: bangalore

PostPosted: Thu Aug 30, 2007 10:12 am
Reply with quote

Hi All,

I have a DB2 table name Employee.The columns are EMP_TYPE,EMP_NO,EMP_NAME,EMP_ADDRESS.
I am writting a cobol program to Get the counts of the rows based on the EMP_TYPE.For eg the values for EMP_TYPE is 10,20,30,40 etc.
I need to get the count for the number of the Employees with EMP_TYPE = 10 ,EMP_TYPE = 20....... .
My question is whether we need a Cursor to get the Counts for each EMP_TYPE or just a single query will do ?


Thanks in Advance
Back to top
View user's profile Send private message
Prajesh_v_p

Active User


Joined: 24 May 2006
Posts: 133
Location: India

PostPosted: Thu Aug 30, 2007 10:23 am
Reply with quote

You might need to use a cursor if you want to retrieve count for more than one emp type and you are not aware of the diffrent emp types available in the emp table.

Thanks,
Prajesh
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Aug 30, 2007 12:51 pm
Reply with quote

If you are on db2 V7 or later:
Code:

SELECT DISTINCT EMP_TYPE
     , COUNT(DISTINCT EMP_TYPE)
FROM your-table
ORDER BY 1
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Aug 30, 2007 1:13 pm
Reply with quote

Sorry, last post sucks. Try

Code:

SELECT EMP_TYPE
    ,  COUNT(EMP_TYPE)
FROM your-table
GROUP BY EMP_TYPE
ORDER BY EMP_TYPE;
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 Select two different counts from SQL... DB2 6
No new posts Checking the total counts inside a re... JCL & VSAM 5
No new posts Is SQLCODE -811 possible while fetchi... DB2 1
No new posts Required Date Format in Include Sort ... DFSORT/ICETOOL 6
No new posts Restart logic by using cursor name in... DB2 1
Search our Forums:

Back to Top