0

Hi,
I want to display the department no. and the no. of employee in each department from EMP Table.(in a Single Row). Pls help me how to write the query for that.
I had one query which display the result in 3 rows.

select deptno, count(*) from emp
group by deptno;

Dptno Count(*)
10 5
20 3
30 4

I want to display this 3 rows in a single-row.
For Eg:

Dpt10 Count(*) Dpt20 Count(*) Dpt30 Count(*)
10 5 20 3 30 4

The output in this forum is not proper but try to understand that the no. 5,3 & 4 should be below count(*) column and 10,20 & 30 should be below deptno.

6
Contributors
7
Replies
20
Views
11 Years
Discussion Span
Last Post by Niteshkmr049
0

select '10 '||sum(a)||' 20 '||sum(b)||' 30 '||sum(c) "Dept vs count(*)" from(select decode(deptno,10,count(Sal)) a, decode(deptno,20,count(Sal)) b, decode(deptno,30,count(Sal)) c from emp group by deptno)
/

0

Hi, you can used stragg function to get the output as ur requirement.

select sys.stragg(column_name||' ') from table_name
where rownum < 5

-1

hello i think this is to simple you write this code
tablename emply
columnname epname,deptno,age,sex
code
select distinct(deptno),epname from emply;

Votes + Comments
zombie...
-1

sorry your answer is
select departmentno,count(empname) as employee from emply group by departmentno;

ok it will work very well thanks Nitesh Srivastva 9718313245

Votes + Comments
zombie
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.