What are COLUMN functions in DB2? Explain with the help of an example

DB2DatabaseBig Data Analytics

The DB2 COLUMN functions are also known as aggregate functions. These functions take the values from a particular column of multiple rows and return a single value.

Below is the list of some most commonly used COLUMN functions.

COLUMN FUNCTION
DESCRIPTION
SUM
Finds the sum of column values
COUNT
Count the number of column values
AVG
Finds the average of column values
MAX
Finds the maximum value in the column
MIN
Finds the minimum value in the column


The COLUMN function can only be used in the SELECT query. For example, if we have to find the average of all the ORDER_TOTAL for the orders placed on 15-08-2020 from the ORDERS table, then we can use the below query.

Example

SELECT AVG(ORDER_TOTAL) FROM ORDERS
   WHERE ORDER_DATE = ‘15-08-2020’
raja
Published on 30-Nov-2020 09:14:43
Advertisements