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
 
to get count of rows in another table for a key in 1 table

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

New User


Joined: 29 Dec 2005
Posts: 10

PostPosted: Mon Feb 09, 2009 11:59 am    Post subject: to get count of rows in another table for a key in 1 table
Reply with quote

I have 2 tables, DEPT & EMPLOYEE.

DEPT:
Dept Name
Dept No
Dept Loc

EMPLOYEE:
Employee Name
Employee Address
Salary
Dept No


I need an SQL to display Dept Name, Dept Loc, Dept No along with count of employees in each Dept.
Can anyone provide me with the query.
Back to top
View user's profile Send private message

dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon Feb 09, 2009 2:35 pm    Post subject:
Reply with quote

Quote:

Can anyone provide me with the query

better than that, we can help you build your own query. what do you have so far?
Back to top
View user's profile Send private message
Srihari Gonugunta

Active User


Joined: 14 Sep 2007
Posts: 295
Location: Singapore

PostPosted: Mon Feb 09, 2009 3:29 pm    Post subject:
Reply with quote

Please try the following query.

Code:
SELECT A.DEPTNAME,A.DEPTNO,A.DEPTLOC,B.CNT FROM
DEPT A, (SELECT DEPTNO, COUNT(*) as CNT from EMPLOYEE
GROUP BY DEPTNO) AS B
WHERE A.DEPTNO=B.DEPTNO
Back to top
View user's profile Send private message
naveengec

New User


Joined: 24 Mar 2007
Posts: 35
Location: pune

PostPosted: Mon Feb 09, 2009 3:35 pm    Post subject: Reply to: to get count of rows in another table for a key in
Reply with quote

Please try it...

select dept_name, dept_loc, dept_No, (select count(B.DEPT_NO) FROM EMPLOYEE B WHERE A.DEPT_NO=B.DEPT_NO) AS COUNT_EMP
FROM DEPT A
Back to top
View user's profile Send private message
i_at_forum

New User


Joined: 29 Dec 2005
Posts: 10

PostPosted: Tue Feb 10, 2009 6:36 pm    Post subject:
Reply with quote

thank you...
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 Update table without cursor Ron Klop DB2 3 Wed Oct 11, 2017 1:06 pm
No new posts Table(Unicode(Graphic) table) loading... muralikrishnan_new DB2 0 Thu Oct 05, 2017 5:10 pm
No new posts Conditional highlighting of rows in I... packerm CLIST & REXX 2 Thu Sep 21, 2017 6:50 pm
No new posts Insert a Row_number into table useit DB2 2 Tue Sep 19, 2017 1:07 pm

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