求一条SQL语句,查"工资高于部门平均水平"的员工...该怎么查啊
表中4个字段:ID,NAME,部门NAME,工资....
------解决方案--------------------------------------------------------
select t1.* from [table] t1 join (select dept,avg(salary)salary2 from [table] group by dept)t2 on t1.dept=t2.dept where t1.salary>t2.salary2
------解决方案--------------------------------------------------------
select * from tb where 工资 > AVG(工资)
WITH B AS (SELECT avg(salary) as salary,dept_id FROM emp GROUP BY dept_id)
SELECT A.id,A.name
FROM emp A,B
WHERE A.dept_id=B.dept_id
AND A.salary>B.salary;
------解决方案--------------------------------------------------------
- SQL code
select a.*from table_name awhere a.Salary>(select avg(b.Salary) from table_name b)