944,017 Members | Top Members by Rank

Ad:
  • Oracle Discussion Thread
  • Unsolved
  • Views: 4216
  • Oracle RSS
Jul 29th, 2006
0

SQL Query Problem

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
manoj201jain is offline Offline
5 posts
since Apr 2006
Oct 1st, 2008
0

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

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)
/
Reputation Points: 10
Solved Threads: 0
Newbie Poster
arvind209 is offline Offline
1 posts
since Oct 2008
Oct 5th, 2008
0

Re: SQL Query Problem

You are supposed tp post the code that you are working on before asing for code(solution)
Featured Poster
Reputation Points: 665
Solved Threads: 427
Posting Genius
debasisdas is offline Offline
6,406 posts
since Feb 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Oracle Forum Timeline: Oracle 10g Screen not showing up
Next Thread in Oracle Forum Timeline: Need help solving this query





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC