mysql 求最小值/最大值

时间:2022-03-09 15:14:12

 计算所有人最低工资和最高工资,需分别用到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;