304 views
0 votes
0 votes
when we calculated avg fun in sql then we exclude the null value or not in count (sum/count)

somewhere it consider null vlaue also in count soomwher not??

wht is actual procedure

2 Answers

2 votes
2 votes

The COUNT(column_name) function returns the number of values (NULL values will not be counted) of the specified column.

The COUNT(*) function returns the number of records in a table either null or non null.

The COUNT(DISTINCT column_name) function returns the number of distinct non null values of the specified column.

1 votes
1 votes

The COUNT(column_name) function returns the number of values (NULL values will not be counted) of the specified column.

The COUNT(*) function returns the number of records in a table either null or non null.

So average salary = sum(salary)/ count (salary).

if a value is null out of 4  then count (salary) will give 3
so average will be sum / 3 while actually result should be divided by 4

Related questions

0 votes
0 votes
1 answer
3
rayhanrjt asked Jan 6, 2023
791 views
Write SQL command to find DepartmentID, EmployeeName from Employee table whose average salary is above 20000.
2 votes
2 votes
1 answer
4
Subhrangsu asked Jun 18, 2022
453 views
Write SQL query to show all employees hired on June 4,1984 (non-default format)emp(empno,ename,job,mgr,hiredate,sal,comm,deptno)