SQL Query Problem

Reply

Join Date: Apr 2006
Posts: 5
Reputation: manoj201jain is an unknown quantity at this point 
Solved Threads: 0
manoj201jain manoj201jain is offline Offline
Newbie Poster

SQL Query Problem

 
0
  #1
Jul 29th, 2006
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.
Last edited by manoj201jain; Jul 29th, 2006 at 11:35 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1
Reputation: arvind209 is an unknown quantity at this point 
Solved Threads: 0
arvind209 arvind209 is offline Offline
Newbie Poster

Re: Query to display no of employees in the department 10, 20,30 in a single row

 
0
  #2
Oct 1st, 2008
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)
/
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 2,082
Reputation: debasisdas will become famous soon enough debasisdas will become famous soon enough 
Solved Threads: 124
debasisdas's Avatar
debasisdas debasisdas is online now Online
Postaholic

Re: SQL Query Problem

 
0
  #3
Oct 5th, 2008
You are supposed tp post the code that you are working on before asing for code(solution)
Share your Knowledge.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC