The SQL AVG function computes the average of the values for the column( or expression) specified as an argument.
We should not give AVG function on CHAR arguments. This function operates only on numeric arguments.
The following example calculates the average salary of each department:
SELECT WORKDEPT, AVG(SALARY) FROM DSN81010.EMP GROUP BY WORKDEPT;
The AVG function is the preferred method of calculating the average of a group of values.
Although an average, in theory, is nothing more than a sum divided by a count, DB2 may not return equivalent values for AVG(COL_NAME) and SUM(COL_NAME)/COUNT(*).
The reason is that the COUNT function will count all rows regardless of value, whereas SUM ignores nulls.
Related posts
-
AI Agents for Beginners: Everything You Need to Know
Learn what AI agents are, how they work, their benefits, use cases, frameworks, and future trends in this complete beginner-friendly guide.
-
Quick SQL Interview Questions for Data Engineers (Little Tricky)
Prepare for Data Engineer interviews with quick SQL interview questions, tricky SQL queries, table creation scripts, joins, window functions, ranking, duplicate records, latest row logic, and real-world examples
-
AWS Glue Crawler Issue with Dynamic S3 Folder Paths? Here’s the Complete Fix
Learn how to fix AWS Glue crawler issues when S3 paths contain dynamically changing folders like hash values or UUIDs. Step-by-step beginner-friendly guide.






