SQL: Count Function, Count(*), Count(ColName), Count(Expression), Count(1)

Опубликовано: 26 Февраль 2025
на канале: GoLearningPoint
142
1

SQL Count() Function

Count(*)
Select Count(*) From Table_Name;
Return total number records in a Table regardless of NULL and Duplicates.
singn denotes everything from a Table.

Count(ColumnName)
All non-null records in a column.

Count(Expression) - Count(1), Count('Hello') etc.
Return all the values regardless of NULL and Duplicates.

Select Count(*),Count(1), Count('HELLO'), Count(DEPTID), Count(*)-Count(DEPTID), SUM(DECODE(DEPTID,NULL,1,0)) ,
SUM(CASE When DEPTID IS NULL Then 0 Else 1 END) as DEPT_NON_NULL
From Employee;

#GoLearningPoint

For Interview questions and other topics -
https://tipsfororacle.blogspot.com/