Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

Versions available for this page: CUBRID 8.2.1 |  CUBRID 8.3.0 |  CUBRID 8.3.1 |  CUBRID 8.4.0 |  CUBRID 8.4.1 |  CUBRID 8.4.3 |  CUBRID 9.0.0 | 

COUNT Function

Description

The COUNT function returns the number of instances in the query results with an entered expression. It also calculates the number of attributes that have a collection attribute and object domain (user-defined class or multimedia class). If the expression is specified in the brace, only instances that are not NULL can be counted. If wildcard (*) is specified, however, all instances are counted even though some instances are duplicated or having NULL. In addition, COUNT function never returns NULL, only returns numbers.

syntax

COUNT ( * | [ DISTINCT | UNIQUE | ALL ] expression )

The COUNT function returns the number of instances for an expression in the parentheses. All instances that meet the conditions of the WHERE clause can be counted by specifying a wildcard (*) symbol. A unique value can be counted by specifying a DISTINCT or UNIQUE keyword before the expression.

  • expression : Specifies the expression to calculate the number.
  • ALL : Used to calculate the number of all the instances of a given expression (default).
  • DISTINCT or UNIQUE : Gets the number of unique values without duplicates.
Example

The following is an example of returning the number of Olympic Games that had a mascot.

SELECT COUNT
FROM olympic
WHERE mascot IN NOT NULL;

Result : 9