Basic SQL Programming Question - Joining 3 tables then sorting

  • Thanks for the help guys

  • #3 looks good.

    For #4, what you want to do is set up a CASE statement. Are you looking for people in each group/range in one query or are you trying to get separate queries for each range?

    You can do something like.

    select

    case

    when salary = 10k and < 20k then count(employeeid)

    else 0

    end 'range 2'

    ....

  • Well, I've tried running 3 and this is what I get in return:

    Msg 208, Level 16, State 1, Line 1

    Invalid object name 'ManagerInfo'.

    On SQL Server Management Studio Express (if that matters)

    For 4, what I am trying to do is similar to what you posted where it will return a table:

    Range Number

    1 2

    2 2

    3 6

    Etc

    Thx

  • check if the table 'ManagerInfo' exist?

    Also see if the owner is different from you or dbo, in which case u'll need to prefix the owner name

    like owner.ManagerInfo



    Pradeep Singh

  • The first post has everything I have...

  • I dont have sample data so cant test for logical accuracy. but the below code runs fine.

    Select Emp.name,Count (ManagerInfo.EmployeeID) from Employee Emp

    Join EmployeeDepartment

    On Emp.EmployeeID=EmployeeDepartment.EmployeeID

    Join DepartmentManager

    On EmployeeDepartment.DepartmentID=DepartmentManager.DepartmentID

    Join Employee ManagerInfo

    On DepartmentManager.ManagerID=ManagerInfo.EmployeeID

    Group by DepartmentManager.ManagerID, emp.name

    Having ( Count (ManagerInfo.EmployeeID))>3



    Pradeep Singh

  • That helped a lot. Thanks!!

  • Thanks again for the help

  • case when salary >= 10000 and salary < 20000 then count(employeeid)

    you need to change this everywhere.



    Pradeep Singh

  • Thanks. That got it to run.

  • can u post the full query? coz i cant find the table name in your query.



    Pradeep Singh

  • Totally wrong stuff... Started over

  • Ahh how can i miss that.. there is some syntax error out there....

    select 'range <$10k'=

    case

    when salary = 10000 and salary = 20000 and salary = 30000 and salary < 40000 then count(employeeid)

    end

    ....

    ....

    ....

    ....

    From employee



    Pradeep Singh

  • I'm confused. Can you please actually edit what it's supposed to say and post the first few sections EXACTLY as they should be so I can see?

    Thanks

  • This stuff was totally wrong too.

Viewing 15 posts - 1 through 15 (of 24 total)

You must be logged in to reply to this topic. Login to reply