Megosztás a következőn keresztül:


MAX (Transact-SQL)

Returns the maximum value in the expression. May be followed by the OVER clause.

Topic link iconTransact-SQL Syntax Conventions

Syntax

MAX ( [ ALL | DISTINCT ] expression )

Arguments

  • ALL
    Applies the aggregate function to all values. ALL is the default.

  • DISTINCT
    Specifies that each unique value is considered. DISTINCT is not meaningful with MAX and is available for ISO compatibility only.

  • expression
    Is a constant, column name, or function, and any combination of arithmetic, bitwise, and string operators. MAX can be used with numeric, character, and datetime columns, but not with bit columns. Aggregate functions and subqueries are not permitted.

    For more information, see Expressions (Transact-SQL).

Return Types

Returns a value same as expression.

Remarks

MAX ignores any null values.

For character columns, MAX finds the highest value in the collating sequence.

Examples

The following example returns the highest (maximum) tax rate.

USE AdventureWorks;
GO
SELECT MAX(TaxRate)
FROM Sales.SalesTaxRate;
GO

Here is the result set.

------
19.60

(1 row(s) affected)

Warning, null value eliminated from aggregate.