计算所有人最低工资和最高工资,需分别用到min()和max()函数。(请注意,MIN和MAX函数会忽略NULL值)
select min(sal) as min_sal , max(sal) as max_sal from emp;
结果:
+---------+---------+ | min_sal | max_sal | +---------+---------+ | 880 | 5000 | +---------+---------+ 1 row in set
搜索每个部门的最低工资和最高工资,还可以使用group by
select deptno,min(sal) as min_sal , max(sal) as max_sal from emp group by deptno;