Skip to main content

Count

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

Constructor

Count(): Count
new Count(): Count

Dual-callable, no arguments — Count always counts rows (count(*)); it does not accept a column expression to count distinct/non-null values of.

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

Select('country', Count().as('total')).from('customers').groupBy('country');
// select country, count(*) total from customers group by country

Properties

KeyTypeReadonlyDescription
_typeSerializationType.COUNT_STATEMENTYesDiscriminates this node during serialization.
_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).

Count().as('total');
// count(*) total

See also