Monday, 13 April 2026

Aggregate Functions in Oracle SQL

                                 Aggregate Functions

                                     POC done by Raghava

 Perform a calculation on multiple records and return a single record

If we want go with aggregate Function’s with other Column’s we Must go with Group by Columns

 AVG

 MIN

 MAX

 SUM

 COUNT

 RULES TO USE Aggregate Functions

 Mostly used with Group by Clause

 -->Columns which are used in select clause with aggregate functions must be available in group by Clause

 Ex:select deptno,job,avg(sal) from xx_emp Group by deptno,job order by deptno;

 Select avg(sal) from xx_emp;

select Max(sal)from xx_emp;

select Min(sal)from xx_emp;

select SUM(sal)from xx_emp;

select count(*)from xx_emp;

If we use count(1)

select count(Null) from xx_emp;

Difference b/w Count (1) and Count (*)

Specific Columns: COUNT(1) does not count the first column of a table; it evaluates the literal "1" for each row and counts how many times it is non-null (which is always).

Recommendation: COUNT(*) is generally preferred as it is the standard SQL syntax and more commonly understood by other developers

COUNT(column_name):

Unlike the two above, COUNT(column_name) behaves differently because it excludes NULL values in that specific column from the final count



 

No comments: