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
-
Tony Robbins Vocabulary: 50 Powerful Words and Phrases to Improve Your English
Learn 50 powerful Tony Robbins vocabulary words and phrases with simple meanings and example sentences to improve your English speaking skills
-
Migrating JSON Files from AWS S3 to PostgreSQL Using AWS Glue and PySpark
Migrating JSON files from AWS S3 to PostgreSQL using AWS Glue and PySpark is one of the most common data engineering challenges teams face today. In this guide, you will learn exactly how to build a production-grade AWS Glue JSON to PostgreSQL migration pipeline — from reading raw JSON files in S3 to writing clean,…
-
5 PySpark Performance Anti-Patterns on Databricks (And How to Fix Them)
Databricks makes scaling big data processing feel almost effortless. Under the hood, however, writing PySpark without understanding how Apache Spark and Delta Lake execute your code can quietly ruin performance, spike DBU costs, and cause out-of-memory (OOM) crashes. Below are 5 common PySpark anti-patterns seen in production, along with exact code fixes to keep your…



