Please Help!

Last Minute revison!

Page 1 of 1

3 Replies - 944 Views - Last Post: 15 May 2009 - 12:50 PM Rate Topic: -----

#1 Addio569   User is offline

  • D.I.C Regular

Reputation: 3
  • View blog
  • Posts: 316
  • Joined: 26-November 08

Please Help!

Posted 14 May 2009 - 02:37 AM

Hi Guys,

just want to cram as much in before the exam.

im using sql.

in a revision question i was asked to List department numbers (deptno) and show how many employees work in each department.

how do I do this??

also I then have to adapt the question to do this:

show only those departments that have 4 or more employees.

again how do I do this?

I tried:

SELECT ename, dept count(*) deptcount
FROM emp
GROUP BY deptno;



but it didnt work!

can someone please help me!

Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Please Help!

#2 Trogdor   User is offline

  • D.I.C Addict
  • member icon

Reputation: 15
  • View blog
  • Posts: 627
  • Joined: 06-October 06

Re: Please Help!

Posted 14 May 2009 - 04:27 AM

firts try
SELECT ename, count(dept) as deptcount
instead

the count function has to count something afterall, not just randomly stand between fieldnames...
Was This Post Helpful? 0
  • +
  • -

#3 noorahmad   User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: Please Help!

Posted 14 May 2009 - 04:39 AM

SELECT COUNT(*) FROM emp;

Was This Post Helpful? 0
  • +
  • -

#4 ahmad_511   User is offline

  • MSX
  • member icon

Reputation: 131
  • View blog
  • Posts: 722
  • Joined: 28-April 07

Re: Please Help!

Posted 15 May 2009 - 12:50 PM

hello,

Quote

to List department numbers (deptno) and show how many employees work in each department.

SELECT deptno, count(ename) as emps_count
FROM emp
GROUP BY deptno;



of course count(ename) here will act just like count(*) because of the grouping but i just type it like this to met the question

how only those departments that have 4 or more employees. you have to use WHER
SELECT deptno, count(ename) as emps_count
FROM emp
WHERE count(ename)>=4
GROUP BY deptno;


This post has been edited by ahmad_511: 15 May 2009 - 12:54 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1