with table_a as (
select deptno,avg(sal) avgsal from emp
)
select a.* from emp a inner join dept b on a.deptno=b.deptno inner join table_a c on a.deptno=c.deptno
and a.sal>c.avgsal
mysql 不支持top命令,但支持limit命令
即 如: select * from table where a>b order by c limit 5.
即为 取出 符合条件a>b的按照C排序的前5条记录
在所有字段前,select后加上top 5
top 取前几条的 你可要试试