DBAsupport.com Forums - Powered by vBulletin
Results 1 to 2 of 2

Thread: Avg number of employees per department per organization?

  1. #1
    Join Date
    Mar 2006
    Posts
    74

    Avg number of employees per department per organization?

    I'd do this:

    Code:
    SELECT
      org,
      avg(cnt_dep)
    FROM
      (
        SELECT
          org,
          count(*) as cnt_dep
        FROM
          emp
        GROUP BY
          org, dep
      )
    GROUP BY
      org
    Would you do any different?

    assume we had a table with:

    ibm, marketing, 3
    ibm, dev, 4
    ibm, hr, 2
    ora, research, 2
    ora, pr, 3
    ora, marketing 7


    and were seeking:
    org, avg_emp_per_dep
    ibm, 3
    ora, 4

  2. #2
    Join Date
    May 2000
    Location
    ATLANTA, GA, USA
    Posts
    3,135
    No need to write in-line view.

    Code:
    SQL> select * from mytable;
    
    ORG DEPTNAME   TOT_DEPT_EMPL
    --- ---------- -------------
    ibm marketing              3
    ibm sales                  6
    ibm accounts              12
    ora marketing              6
    ora sales                 10
    ora accounts              20
    
    6 rows selected.
    
    SQL> select org, avg(tot_dept_empl) from mytable 
      2  group by org;
    
    ORG AVG(TOT_DEPT_EMPL)
    --- ------------------
    ora                 12
    ibm                  7

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width