mysql 求最小值/最大值
计算所有人最低工资和最高工资,需分别用到min()和max()函数。(请注意,MIN和MAX函数会忽略NULL值)
1
select min(sal) as min_sal , max(sal) as max_sal from emp;
结果:
1
2
3
4
5
6
±————±————+
| min_sal | max_sal |
±————±————+
| 880 | 5000 |
±————±————+
1 row in set
搜索每个部门的最低工资和最高工资,还可以使用group by
1
select deptno,min(sal) as min_sal , max(sal) as max_sal from emp group by deptno;
还没有评论,来说两句吧...