COUNT

Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API

Counts the number of input rows or non-null values.

Syntax

count(*)
count(<expression>)
count(DISTINCT <expression>)

Arguments

Required

  • *: Counts all rows, including rows with NULL values.
  • <expression>: Counts rows where the expression is not NULL.

Optional

  • DISTINCT: Counts only distinct non-null values.

Returns

Returns a bigint representing the count.

Considerations

  • Unlike other aggregates, count returns 0 (not NULL) for empty sets.

Examples

Count All Rows

Count the total number of rows.

SELECT count(*) AS total_orders
FROM orders;

Count Non-NULL Values

Count the rows with non-null values.

SELECT count(email) AS customers_with_email
FROM customers;

Count Distinct Values

Count the unique values.

SELECT count(DISTINCT category) AS category_count
FROM products;

Count by Group

Count the rows per group.

SELECT department, count(*) AS employee_count
FROM employees
GROUP BY department;

Related Documentation