COUNT

Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API

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

Syntax 

1count(*)
2count(<expression>)
3count(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.

1SELECT count(*) AS total_orders
2FROM orders;

Count Non-NULL Values 

Count the rows with non-null values.

1SELECT count(email) AS customers_with_email
2FROM customers;

Count Distinct Values 

Count the unique values.

1SELECT count(DISTINCT category) AS category_count
2FROM products;

Count by Group 

Count the rows per group.

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

Related Documentation