View previous topic :: View next topic
|
Author |
Message |
k.junaid83
New User
Joined: 19 Apr 2006 Posts: 22 Location: bangalore
|
|
|
|
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 |
|
|
Prajesh_v_p
Active User
Joined: 24 May 2006 Posts: 133 Location: India
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
|