SQL Basics

 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Tutorialized ForumsDatabasesSQL Basics

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Tutorialized Forums Sponsor:
  #1  
Old January 30th, 2012, 08:37 AM
glennburke glennburke is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Jan 2012
Posts: 1 glennburke User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 15 sec
Reputation Power: 0
HR Schema query

Hi all,

Wondering if anybody can answer this? I'm trying to run a query against the sample HR Schema that is available in Oracle. The schema consist's of an employees table and a departments table. The employee table includes employees name, id number and manager id number. Some employees are managers so their id numbers are present in the manager id number field for other employees.

I'm trying to count the number of employees per manager but return the data so the managers name and the count total per manager are shown.

I have written two scripts that perform the tasks I am trying to do separately. The first script returns the number of employees per manger id number:

SELECT MANAGER_ID, COUNT(MANAGER_ID)
FROM EMPLOYEES
GROUP BY MANAGER_ID
HAVING COUNT(MANAGER_ID) > 0;

The second script identifies who is a manager by checking employee id number against manager id number and report the employees last name:

SELECT E.LAST_NAME, D.MANAGER_ID, E.EMPLOYEE_ID
FROM EMPLOYEES E, DEPARTMENTS D
WHERE E.EMPLOYEE_ID = D.MANAGER_ID

As I said I'm trying to show the last name in one column with the total in the next column.

Can anybody help. Thanks.

Reply With Quote
  #2  
Old February 2nd, 2013, 02:39 PM
Mirdita Mirdita is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 1 Mirdita User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 44 m 36 sec
Reputation Power: 0
Im not a guru but i think i can help you with this one,maybe u havent yet gone into joins in sql..here is the code:

select b.last_name,count(e.employee_id) from employees e join employees b on e.manager_id=b.employee_id group by b.last_name

Last edited by Mirdita : February 2nd, 2013 at 02:47 PM.

Reply With Quote
Reply

Viewing: Tutorialized ForumsDatabasesSQL Basics > HR Schema query


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap