TRENDING TOPICS

×

COUNT(), AVG(), SUM() Functions

The SQL COUNT(), AVG(), SUM() Functions used to calculate the specific values:

  • The COUNT() function returns the number of ROWS that matches.
  • The AVG() function used to calculate the average value of a numeric column.
  • The SUM() function returns the total SUM of a numeric column.

Syntax of COUNT() function

SELECT COUNT (column_name)
FROM table_name
WHERE [condition];

Syntax of AVG() function

SELECT AVG (column_name)
FROM table_name
WHERE [condition];

Syntax of SUM() function

SELECT SUM (column_name)
FROM table_name
WHERE [condition];

Example of COUNT(), AVG(), SUM()

Sample Orders Table

ORD_ID ORD_DATE ORD_AMOUNT ADVANCE_AMOUNT
0210 10/01/2019 4000 1500
0211 10/22/2019 3500 500
0222 10/29/2019 1000 100
0225 12/01/2019 5300 3000
0230 12/17/2019 1300 200
0253 12/20/2019 3100 1500

Example of COUNT() Function

SELECT COUNT (ORD_ID)
FROM ORDERS;

Result Look Like

ORD_ID
6

Example of AVG() Function

SELECT AVG (ADVANCE_AMOUNT)
FROM ORDERS;

Result Look Like

ADVANCE_AMOUNT
1216.66666

Example of SUM() Function

SELECT SUM (ORD_AMOUNT)
FROM ORDERS;

Result Look Like

ORD_AMOUNT
18,200

© 2021 GDATAMART.COM (All Rights Reserved)