SQL Max 函数

SQL Max() 函数返回一个表达式的最大值。

SQL Max() 函数语法

SELECT MAX(expression)
FROM 数据表
WHERE predicates

SQL Max() 函数范例

数据表: Employees

EmployeeId FirstName LastName Department Salary
203 Mazojys Fxoj Finance 78000
204 Jozzh Lnanyo Finance 45800
205 Syllauu Dfaafk Finance 57000
206 Gecrrcc Srlkrt Finance 62000
302 Jssme Bdnaa Development 75000
303 Dnnaao Errllov Development 55000
304 Tyoysww Osk Development 49000

例1
我们想知道所有职员中的最高工资:

SELECT Max(Salary) AS "Highest salary"
FROM Employees

结果会类似于:

Highest salary
78000

例2
如果我们想知道每个部门的最高工资,可以使用GROUP BY子句:

SELECT Department, MAX(Salary) AS "Highest salary"
FROM Employees
GROUP BY Department

结果会类似于:

Department Highest salary
Finance 78000
Development 75000