COUNT (Lakehouse v1)
The COUNT() function returns the number of records returned by a SELECT query.
Analyze Syntax
Section titled “Analyze Syntax”func.count(<column>)Analyze Examples
Section titled “Analyze Examples”func.count(table.grade).alias('count_valid_grades')
| count_valid_grades ||--------------------|| 4 |SQL Syntax
Section titled “SQL Syntax”COUNT(<expr>)Arguments
Section titled “Arguments”| Arguments | Description |
|---|---|
<expr> | Any expression. This may be a column name, the result of another function, or a math operation. * is also allowed, to indicate pure row counting. |
Return Type
Section titled “Return Type”An integer.
SQL Examples
Section titled “SQL Examples”Create a Table and Insert Sample Data
CREATE TABLE students ( id INT, name VARCHAR, age INT, grade FLOAT NULL);
INSERT INTO students (id, name, age, grade)VALUES (1, 'John', 21, 85), (2, 'Emma', 22, NULL), (3, 'Alice', 23, 90), (4, 'Michael', 21, 88), (5, 'Sophie', 22, 92);Query Demo: Count Students with Valid Grades
SELECT COUNT(grade) AS count_valid_gradesFROM students;Result
| count_valid_grades ||--------------------|| 4 |