SQL-J Language Reference,
Page 67 of 118


[top]
[prev]
[next]
Documentation Top
Global Index
Reference Manual
TOC Index
Grammar index
Developer's Guide
TOC Index
Tuning Cloudscape
TOC Index

COUNT

COUNT is an aggregate function that counts the number of rows accessed in an expression (see “Aggregates (Set Functions)”). COUNT is allowed on all types of expressions, even those that evaluate to Java data types.

Syntax

COUNT ( [ DISTINCT | ALL ] Expression )

The DISTINCT qualifier eliminates duplicates. The ALL qualifier retains duplicates. ALL is assumed if neither ALL nor DISTINCT is specified. For example, if a column contains the values 1, 1, 1, 1, and 2, COUNT(col) returns a greater value than COUNT(DISTINCT col).

Only one DISTINCT aggregate expression per SelectExpression is allowed. For example, the following query is not allowed:

-- query not allowed
SELECT COUNT (DISTINCT flying_time), SUM (DISTINCT miles)
FROM Flights

An Expression can contain multiple column references or expressions, but it cannot contain another aggregate or subquery. If an Expression evaluates to NULL, the aggregate is not processed for that value.

The resulting data type is LONGINT.

Example

-- Count the number of distinct last names AND the total number
-- of last names
SELECT COUNT (DISTINCT person.getLastName()),
    COUNT(person.getLastName())
FROM People
-- Count the number of countries in each region,
-- show only regions that have at least 2
SELECT COUNT (country), region
FROM Countries
GROUP BY region
HAVING COUNT (country) > 1
-- counting a Java data type
SELECT COUNT (city)
FROM Cities
[top]
[prev]
[next]


Cloudscape Version 3.0
For technical support, go to: www.cloudscape.com and click Support.
Copyright © 1998 and 1999 Cloudscape, Inc. All rights reserved.