为此,您可以使用MAX()
。语法如下-
select MAX(yourColumnName) AS anyAliasName from yourTableName;
让我们创建一个表-
mysql> create table demo44 −> ( −> employee_id int not null auto_increment primary key, −> employee_name varchar(20), −> employee_salary int −> ) −> ;
借助insert命令将一些记录插入表中-
mysql> insert into demo44(employee_name,employee_salary) values('John',3000); mysql> insert into demo44(employee_name,employee_salary) values('David',4500); mysql> insert into demo44(employee_name,employee_salary) values('Bob',3500); mysql> insert into demo44(employee_name,employee_salary) values('Carol',5500); mysql> insert into demo44(employee_name,employee_salary) values('Mike',4900);
使用select语句显示表中的记录-
mysql> select *from demo44;
这将产生以下输出-
+-------------+---------------+-----------------+ | employee_id | employee_name | employee_salary | +-------------+---------------+-----------------+ | 1 | John | 3000 | | 2 | David | 4500 | | 3 | Bob | 3500 | | 4 | Carol | 5500 | | 5 | Mike | 4900 | +-------------+---------------+-----------------+ 5 rows in set (0.00 sec)
以下是选择最高薪水的查询-
mysql> select MAX(employee_salary) AS Highest_Salary from demo44;
这将产生以下输出-
+----------------+ | Highest_Salary | +----------------+ | 5500 | +----------------+ 1 row in set (0.00 sec)