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
 

 

SQL query to display

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Mainframe Interview Questions
View previous topic :: :: View next topic  
Author Message
murali_andaluri
Currently Banned

New User


Joined: 07 May 2005
Posts: 22

PostPosted: Thu Oct 04, 2007 3:57 pm    Post subject: SQL query to display
Reply with quote

Hi Friends,

i need SQL query for below reqirement

EMPLOYEE table, with columns EMPID, DEPTID, SALARY.

Write SQL Query to display

a. DEPTID & Number of employees (showing all departments)
b. DEPTID & Number of employees (showing only departments that have > 10 employees)
c. Count of departments that have > 10 employees
Back to top
View user's profile Send private message

raviprasath_kp
Warnings : 1

New User


Joined: 20 Feb 2005
Posts: 65
Location: chennai

PostPosted: Thu Oct 04, 2007 4:57 pm    Post subject: Reply to: SQL query to display
Reply with quote

a. DEPTID & Number of employees (showing all departments)
select depid, count(empid) from employeetable;

b. DEPTID & Number of employees (showing only departments that have > 10 employees)

select depid,count(empid) employeetable
where count(empid) < 10
c. Count of departments that have > 10 employees
same vice versa

please correct me if i am wrong
Back to top
View user's profile Send private message
mahi

New User


Joined: 04 Apr 2006
Posts: 86
Location: Pune

PostPosted: Thu Oct 04, 2007 5:16 pm    Post subject:
Reply with quote

You have to use the group by function to get the number of employyees din a dept...
Back to top
View user's profile Send private message
mahi

New User


Joined: 04 Apr 2006
Posts: 86
Location: Pune

PostPosted: Thu Oct 04, 2007 5:24 pm    Post subject:
Reply with quote

Please go through this link.
http://www.ibmmainframes.com/viewtopic.php?t=14746&highlight=
Back to top
View user's profile Send private message
nuthan

Active User


Joined: 26 Sep 2005
Posts: 146
Location: Bangalore

PostPosted: Thu Oct 04, 2007 5:32 pm    Post subject:
Reply with quote

HI,

TRY THIS


SELECT DEPTID, COUNT(EMPID) FROM EMPLOYEE GROUP BY DEPTID;

SELECT DEPTID, COUNT(EMPID) FROM EMPLOYEE GROUP BY DEPTID HAVING COUNT(EMPID) > 10;

SELECT COUNT(*) FROM EMPLOYEE GROUP BY
DEPTID HAVING COUNT(EMPID) > 10;
Back to top
View user's profile Send private message
murali_andaluri
Currently Banned

New User


Joined: 07 May 2005
Posts: 22

PostPosted: Fri Oct 05, 2007 11:35 am    Post subject: Reply to: SQL query to display
Reply with quote

Hi Nutan,

thank you very much for your quick response.
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 -> Mainframe Interview Questions 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 1 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 Display ZEDLMSG without Pressing F1 &... anandgbe CLIST & REXX 8 Thu Dec 15, 2016 4:20 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am


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