MySQL MIN() 和 MAX() 函数
MySQL MIN() 和 MAX() 函数
SQL MIN() 函数返回所选列中的最小值。
SQL MAX() 函数返回所选列中的最大值。
MIN() 语法
SELECT MIN(column_name)
FROM table_name
WHERE condition;MAX() 语法
SELECT MAX(column_name)
FROM table_name
WHERE condition;演示数据库
Below is a selection from the "Products" table in the Northwind sample database (以下是 Northwind 示例数据库中的 "Products" 表的选择结果)
| ProductID | ProductName | SupplierID | CategoryID | Unit | Price |
|---|---|---|---|---|---|
| 1 | Chais | 1 | 1 | 10 boxes x 20 bags | 18 |
| 2 | Chang | 1 | 1 | 24 - 12 oz bottles | 19 |
| 3 | Aniseed Syrup | 1 | 2 | 12 - 550 ml bottles | 10 |
| 4 | Chef Anton's Cajun Seasoning | 2 | 2 | 48 - 6 oz jars | 22 |
| 5 | Chef Anton's Gumbo Mix | 2 | 2 | 36 boxes | 21.35 |
MIN() 示例
以下 SQL 语句查找最便宜产品的价格
MAX() 示例
以下 SQL 语句查找最贵产品的价格