count
Count the rows of an aggregate result set
Syntax
COUNT({* | [DISTINCT] column_var})
Arguments
| * | All columns of the result set. |
| column_var | The name of a column or one of the tables referenced in the FROM clause. |
Description
This function computes the total number of rows in each aggregate. If DISTINCT is specified with a column name reference then duplicate values of the name column are not included in the count.
A "select count(*) from table_name" quickly returns the number of rows contained in the specified table.
A "select count(*) from table_spec" returns the cardinality (the number of rows) of the specified table. RaimaDB automatically maintains this count for every table allowing the count to be returned from a single call that does not require a database access. SQL fetches the count value without having to apply a lock to the table. Hence, the value that is fetched is "dirty"—meaning that it will account for any uncommitted INSERT or DELETE statements that have been executed by other connections. In order to fetch a "clean" value, the application should either first execute a "start trans read only" or an explicit "lock table" statement prior to the "select count(*) from table_spec".
Example
open nsfawards;
select count(*) from award;
count(*)
132365
select state, count(*) from sponsor, award
where sponsor_nm = name
group by 1 having count(*) > 100;
state count(*)
AK 637
AL 1085
AR 406
AZ 2917
CA 16923
CO 3353
...
VT 333
WA 3218
WI 2582
WV 294
WY 382