count_distinct

count_distinct — aggregate function to return the count of rows in the specified column that have distinct values

SYNOPSIS

count_distinct (expr)

DESCRIPTION

This function returns the count of rows in the specified column that have distinct values. The expr argument must be a literal column name in the current table, or a simple expression that resolves to a column name.

EXAMPLE

This example shows how to use dynamic aggregation using this function. In the Hello LiveView sample, create a query that finds the count_distinct value from a column of the ItemSales table. Follow these steps:

  1. In LiveView Desktop connected to a server running the Hello LiveView sample, select the ItemsSales table from the Tables pane of the LiveView Tables view.

  2. In the Select field, enter:

    count_distinct(Item) as NumItems
    
  3. Make sure the Query field is empty.

  4. Click Open Query.

The query results open in a grid view. LiveView Server recalculates the NumItems value whenever the rows returned by the query predicate change.

SEE ALSO

This LiveView aggregate function is based on the count_distinct aggregate function in the StreamBase expression language.