读书人

求一条简单的SQL语句解决方案

发布时间: 2013-09-11 16:59:35 作者: rapoo

求一条简单的SQL语句
求一条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)
我的异常网推荐解决方案:软件开发者薪资,http://www.myexception.cn/other/1391128.html

读书人网 >其他数据库

热点推荐