一个表(table1)里面有四个字段:员工编号(eno),员工部门编号(dept),员工姓名(ename)和工资(salary)1、输出每个部门的工资总和(只输出工资总和一项,其他的项不要)
2、输出每个部门工资高于该部门平均工资的员工姓名(只要姓名一项,其他的项不要)

解决方案 »

  1.   

    1.
    select dept,sum(isnull(salary,0)) from table1 group by dept
      

  2.   

    1.select sum(salary) from table1 group by dept
    2.select ename,dept from table1 group by dept having(salary)>avg(salary)
      

  3.   

    1、输出每个部门的工资总和(只输出工资总和一项,其他的项不要)select sum(salary) as salary from table1 group by dept2、输出每个部门工资高于该部门平均工资的员工姓名(只要姓名一项,其他的项不要)select   
        a.name
    from 
        table1 a,
        (select dept,avg(salary) as salary from table1 group by dept) b
    where
        a.dept=b.dept and a.salary>b.salary
      

  4.   

    select sum(salary) as salary from table1 group by dept
    select ename from table1 group by dept having(salary)>avg(salary)
      

  5.   

    1.
    select dept,sum(isnull(salary,0)) as salary from table1 group by dept2.
    select ename from table1 a,
    (
    select dept,avg(isnull(salary,0)) as salary from table1 group by dept) b
    where a.dept = b.dept and a.salary > b.salary
      

  6.   

    2.
    select ename
    from table1
    where salary>(select avg(salary) from table1 a where a.dept=table1.dept group by dept)