mysql 求最小值/最大值

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

  

上一篇:oracle 随笔


下一篇:python,django做中间件屏蔽非法访问