Skip to main content

Max

Builds a max(expression) expression, usable anywhere an SQL element is accepted (typically as a Select column).

Constructor

Max(expression: any): Max
new Max(expression: any): Max

Dual-callable. expression is converted through the active SerializeContext (so a string, literal, Field, or Raw are all accepted). Serializes to an empty string if expression is falsy.

import { Max, Select } from '@sqb/builder';

Select('country', Max('age').as('oldest')).from('customers').groupBy('country');
// select country, max(age) oldest from customers group by country

Properties

KeyTypeReadonlyDescription
_typeSerializationType.MAX_STATEMENTYesDiscriminates this node during serialization.
_expressionanyNoThe argument passed to the constructor.
_aliasstring | undefinedNoSet by .as().

Methods

as()

as(alias: string): this

Sets an alias, rendered as a trailing alias after the closing paren (no AS keyword).

Max('age').as('oldest');
// max(age) oldest

See also