select B.dept_name,
       [平均工资]=avg(A.salary)
from employee A
join deptment B on A.dept_id=B.dept_id
group by B.dept_name
having avg(A.salary)>5000

解决方案 »

  1.   

    select
        部门名称 = a.dept_name,
        平均工资 = avg(b.salary)
    from
        deptment a
        employee b
    where
        a.dept_id = b.dept_id
    group by
        a.dept_name
    having 
        avg(b.salary)>5000
      

  2.   


    create table employee (id int,dept_id int,name varchar(8),salary int)
    insert employee select 1,1,'cpp',8000
    union all select 2,1,'yp',7000
    union all select 3,1,'mg',6000
    union all select 4,2,'qwe',1000
    union all select 5,2,'wff',3000
    union all select 6,2,'yx',2000
    union all select 7,2,'sx',8000
    union all select 8,3,'jy',2000
    union all select 9,3,'xx',4000
    create table deptment(id int,dept_id int,dept_name varchar(8))
    insert deptment select 1,1,'市场部'
    union all select 2,2,'技术部'
    union all select 3,3,'财务部'    select dept_name,name,avg(salary) avg from employee e join deptment d 
    on e.dept_id=d.dept_id group by dept_name,name having avg(salary)>5000
      

  3.   

    select e.dept_id,dept_name,avg(salary)  avg from employee e join deptment d 
    on e.dept_id=d.dept_id group by e.dept_id,dept_name having avg(salary)>5000