Mastering the COUNT() Aggregate Function in SQL: A Comprehensive Guide

Rumman Ansari   Software Engineer   2024-07-19 02:08:58   5561  Share
Subject Syllabus DetailsSubject Details
☰ TContent
☰Fullscreen

Table of Content:

The COUNT() function returns the number of rows that matches a specified criteria.

The AVG() function returns the average value of a numeric column.

The SUM() function returns the total sum of a numeric column.

Syntax:


SELECT COUNT(column_name)
FROM table_name
WHERE condition;

We will apply COUNT function in this below table:

We will find the how may employee are available

EmpId

EmpName

EmpAddress

EmpSalary

EmpDept

11

Rambo

Kolkata

30000

ADMIN

21

Inza

Bihar

31000

SALES

32

Samser

Kolkata

32000

IT

41

Kamran

Hydrabad

33000

ITIS

52

Azam

Kolkata

33000

ITIS

Example: COUNT

Code:


SELECT COUNT(EmpId) AS NoOfEmployee FROM EmployeeDetails

Output:

The above code will produce the following result-


NoOfEmployee
5