Home > Database > SQL > body text

Usage of min function in sql

下次还敢
Release: 2024-05-07 06:03:15
Original
614 people have browsed it

The MIN() function in SQL is used to find the minimum value in a specified column, and the syntax is MIN(expression). It is used to find the minimum value in a set of values, determine the minimum value for comparison or filtering, ignore NULL values, and can be used in conjunction with other functions and operators.

Usage of min function in sql

Usage of MIN() function in SQL

MIN() function is used to find the minimum value in a specified column .

Syntax:

<code>MIN(expression)</code>
Copy after login

Where:

  • expression: The column or expression to find the minimum value.

Usage:

MIN() function can be used in the following scenarios:

  • Find the minimum value in a set of values
  • Determine minimum value for comparison or filtering

Example:

<code>-- 查找表 "sales" 中 "price" 列的最小值
SELECT MIN(price) FROM sales;

-- 查找每个客户购买的最便宜商品的价格
SELECT customer_id, MIN(price) AS cheapest_product_price
FROM sales
GROUP BY customer_id;</code>
Copy after login

Notes:

  • MIN() function ignores NULL values.
  • If the expression contains text values, the MIN() function returns the first text value.
  • The MIN() function can be used in conjunction with other functions and operators.

Other options:

The MIN() function has some optional parameters that can be used to further control the behavior of the function:

  • DISTINCT: is used to eliminate duplicate values.
  • ALL: is used to include all values, including NULL values.
  • FILTER (predicate): Used to specify a condition. Only values ​​that meet the condition will be considered.

The above is the detailed content of Usage of min function in sql. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!