4 Replies - 1769 Views - Last Post: 26 October 2012 - 04:21 AM Rate Topic: -----

#1 uperkurk  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 48
  • Joined: 22-April 12

SQL Query sum.

Posted 25 October 2012 - 11:28 AM

Hey guys, I'm trying to work out what query I need for this.

"The query must show how many employees are in each department. It should produce as a result a 2-column table with WORKDEPT as the first column and the number of people in each department as a second column named SIZE (a name you create in your query)

So this is what I have in my head.

Select EMPNO.EMPLOYEE from INNERJOIN DEPTNAME where {....}

What is the syntax to count the total number of employees from each department? The thing is I need to use the QBE but I'm just not sure. Any tips?

Attached Image

Is This A Good Question/Topic? 0
  • +

Replies To: SQL Query sum.

#2 Ionut  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 385
  • View blog
  • Posts: 1,057
  • Joined: 17-July 10

Re: SQL Query sum.

Posted 25 October 2012 - 11:34 AM

You have to use the aggragate function called "sum" and make a group by deptno
select deptno, count(*) from (join tables here) group by deptno


This post has been edited by Ionut: 25 October 2012 - 11:34 AM

Was This Post Helpful? 0
  • +
  • -

#3 uperkurk  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 48
  • Joined: 22-April 12

Re: SQL Query sum.

Posted 25 October 2012 - 12:08 PM

select DEPTNO, count(*) from ( DEPARTMENT INNERJOIN EMPLOYEE ) group by deptno;



Invalid innerjoin syntax it says. Just one question though, what is the query saying in english?
Was This Post Helpful? 0
  • +
  • -

#4 Ionut  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 385
  • View blog
  • Posts: 1,057
  • Joined: 17-July 10

Re: SQL Query sum.

Posted 26 October 2012 - 01:41 AM

Here you can find the correct syntax for inner join.

Quote

Just one question though, what is the query saying in english?

This is an odd question...
It says to db engine to select from department and employee(that linked togheter by a key - check the link above) only the the department number and the employees count on each department("on each" is said by group by)
Was This Post Helpful? 1
  • +
  • -

#5 uperkurk  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 48
  • Joined: 22-April 12

Re: SQL Query sum.

Posted 26 October 2012 - 04:21 AM

I fixed it, thanks :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1