Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Simple Query

FatalsniperFatalsniper Member Posts: 55
Hi there,

I got this query and I couldn't think of an optimal way to solve it.

What do you think?

I have his table with Relatives of an employee.(Employees->Relatives)

I have to answer how many employees have a group of x persons

Example,

Result:

Employees_Amount........Family_Group
----------------........------------
20............................1
100...........................2
153...........................4
200...........................6


Instance: I got 100 employees that have 2 family members(Relatives)

I couldn't figure the query.

Thanks in advance...

Comments

  • ShanooShanoo Member Posts: 32
    Hi,

    Try this:

    Select Count(EmpID) As Employees_Amount, Family_Group From
    (Select E.EmpID As EmpID, Count(ID) As Family_Group
    From Employees E
    Inner Join Relatives R
    On E.EmpID = R.EmpID
    Group By E.EmpID) As T
    Group By Family_Group

    - HTH
Sign In or Register to comment.