Results 1 to 6 of 6

Thread: Query for Number of Employees

  1. #1
    Junior Member
    Join Date
    Jan 2007
    Answers
    6

    Question Query for Number of Employees

    Hi all,

    Can you give me the query for
    Say suppose the table "EMP" contains 2006 th year record only:

    So in 2006 "On which month , the maximum number of employees have been joined in each and every department"



    The output should contain the following columns:
    1. Department ID
    2. Month
    3. emp_count .

    Regards,
    Prasath.


  2. #2
    Expert Member
    Join Date
    Jun 2006
    Answers
    410

    Re: Query for Number of Employees

    Hi try this query,

    select deptno
    ,to_char(hiredate,'Month') month
    ,count(*) "NEW EMPLOYEES"
    from emp
    group by deptno
    ,to_char(hiredate,'Month')

    The above query returns number of employees joined in each month for each department. You can also include year in the group by clause if you have records for more than one year.

    But i could not understand,

    the maximum number of employees have been joined in each and every department...

    My query does not find maximum of anything...it just counts number of new hires.


  3. #3
    Expert Member
    Join Date
    Nov 2006
    Answers
    518

    Re: Query for Number of Employees

    This will work

    Select top 1 Month(DeleteDate) as Mnth, count(*) as Cnt from ItemsDeleted group by Month(DeleteDate) order by Count(*) DESC

    Lack of WILL POWER has caused more failure than
    lack of INTELLIGENCE or ABILITY.

    -sutnarcha-

  4. #4
    Junior Member
    Join Date
    Jan 2007
    Answers
    6

    Re: Query for Number of Employees

    Maximum number of employees means,
    say suppose in dept 10 ,
    there were 5 no of emps joined in Jan,
    there were 10 no of emps joined in FEb and
    there were 2 no of emps joined in March.
    So the O/P should get the Feb month record for dept 10, since it is having the maximum number emps count.

    Hence pls give me the exact query.
    Regards
    Prasath


  5. #5
    Junior Member
    Join Date
    Jan 2007
    Answers
    6

    Re: Query for Number of Employees

    Quote Originally Posted by jamesravid View Post
    Hi try this query,

    select deptno
    ,to_char(hiredate,'Month') month
    ,count(*) "NEW EMPLOYEES"
    from emp
    group by deptno
    ,to_char(hiredate,'Month')

    The above query returns number of employees joined in each month for each department. You can also include year in the group by clause if you have records for more than one year.

    But i could not understand,

    the maximum number of employees have been joined in each and every department...

    My query does not find maximum of anything...it just counts number of new hires.
    Maximum number of employees means,
    say suppose in dept 10 ,
    there were 5 no of emps joined in Jan,
    there were 10 no of emps joined in FEb and
    there were 2 no of emps joined in March.
    So the O/P should get the Feb month record for dept 10, since it is having the maximum number emps count.

    Hence pls give me the exact query.
    Regards


  6. #6
    Expert Member
    Join Date
    Nov 2006
    Answers
    518

    Re: Query for Number of Employees

    Ok got it now,

    But you will have to wait until I get to work on it.

    Lack of WILL POWER has caused more failure than
    lack of INTELLIGENCE or ABILITY.

    -sutnarcha-

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact