在 MySQL 中选择最高工资?
mysqlmysqli database
为此,您可以使用 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 −> ) −> ; Query OK, 0 rows affected (1.27 sec)
使用 insert 命令向表中插入一些记录 −
mysql> insert into demo44(employee_name,employee_salary) values('John',3000); Query OK, 1 row affected (0.13 sec) mysql> insert into demo44(employee_name,employee_salary) values('David',4500); Query OK, 1 row affected (0.12 sec) mysql> insert into demo44(employee_name,employee_salary) values('Bob',3500); Query OK, 1 row affected (0.12 sec) mysql> insert into demo44(employee_name,employee_salary) values('Carol',5500); Query OK, 1 row affected (0.15 sec) mysql> insert into demo44(employee_name,employee_salary) values('Mike',4900); Query OK, 1 row affected (0.13 sec)
使用 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)