Skip to content
Related Articles

Related Articles

Improve Article

SQL COUNT(), AVG() and SUM()

  • Last Updated : 13 Aug, 2020
Geek Week
  1. SQL COUNT() Function :
    The COUNT() function provides the number of rows that matches a specified condition.

    COUNT() Syntax –

    SELECT COUNT(column_name)
    FROM table_name
    WHERE condition; 
  2. SQL AVG() Function :
    The AVG() function provides the average value of a numeric column.

    AVG() Syntax –

    SELECT AVG(column_name)
    FROM table_name
    WHERE condition;
    
  3. SQL SUM() Function :
    The SUM() function provides the total sum of a numeric column.



    SUM() Syntax –

    SELECT SUM(column_name)
    FROM table_name
    WHERE condition;
    



Let us assume, we have a table “GeeksTab”.

NameCitySalaryIDDOJ
AbcDelhi45001346-Aug
DfeNoida65002454-March
DefJaipur54005462-July
MnoNoida78004327-June
JklJaipur54007689-July
LmnDelhi78009878-June
IjkJaipur67006545-June

  1. COUNT() Example :
    The following SQL statement finds the number of Names in the “GeeksTab” table :
    SELECT COUNT(Name)
    FROM GeeksTab; 

    Output –

    7 
  2. AVG() Example :
    The following SQL statement finds the average price of salary in the “GeeksTab” table :
    SELECT AVG(Salary)
    FROM GeeksTab; 

    Output –

    6300 
  3. SUM() Example :
    The following SQL statement will find the sum of the Salary in the “GeeksTab” table :
    SELECT SUM(Salary)
    FROM GeeksTab; 

    Output –

    44100 

Attention reader! Don’t stop learning now. Learn SQL for interviews using SQL Course  by GeeksforGeeks.

My Personal Notes arrow_drop_up
Recommended Articles
Page :