Discussion Locked

Oracle problem coding...

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Let me first off thank you for helping me.

The problem is as stated:

I'm trying to create a report from the EMP and SALGRADE tables. The report counts total employees by department and counts the department's employee by salary grade.

The result is suppose to look like this:

Total Grade 1 Grade 2 Grade 3 Grade 4 Grade 5
---- ----- ------ ------ ------ ------- 3 1 1 1
5 2 3
6 1 2 2 1

Thanks again for all who can help me code this in Oracle. Before the the Total it has the "DNAME"

Henry

5 replies

by d. brinson

I do not know how to accomplish your task in
unenhanced SQL. Is PL/SQL supported in your environment? How about a report writer such as SQR? If none of these things are supported, your best bet may be to break down the problem into 2 selects (one for the total number of employees in a department and a second one for total number of people in a department in a pay grade) and merging them elsewhere - such as in Excel.

by finluca

I think you will be able to get the report using the following SQL statement:

Select
emp.deptname,
emp.empcount,
grade.grade1cnt,
grade.grade2cnt,
grade.grade3cnt,
grade.grade4cnt,
grade.grade5cnt
From
(Select Count(*)empcount, deptname
from emp
group by deptname) emp,
(Select
deptname,
Decode(grade, '1', count(*)) grade1cnt,
Decode(grade, '2', count(*)) grade2cnt,
Decode(grade, '3', count(*)) grade3cnt,
Decode(grade, '4', count(*)) grade4cnt,
Decode(grade, '5', count(*)) grade5cnt
from
salgrade
group by
deptname) grade
Where
emp.deptname=grade.deptname

The first select in the from clause will get you the count of employees by department. The second one will get the count of salary grades by department. These two are then joined by the department name.

This discussion is closed to new replies.