The Wayback Machine - https://web.archive.org/web/20240105170720/https://www.geeksforgeeks.org/sql-count-avg-and-sum/
Open In App
Related Articles

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

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report
  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”.

Name City Salary ID DOJ
Abc Delhi 4500 134 6-Aug
Dfe Noida 6500 245 4-March
Def Jaipur 5400 546 2-July
Mno Noida 7800 432 7-June
Jkl Jaipur 5400 768 9-July
Lmn Delhi 7800 987 8-June
Ijk Jaipur 6700 654 5-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 
Unlock the Power of Placement Preparation!
Feeling lost in OS, DBMS, CN, SQL, and DSA chaos? Our Complete Interview Preparation Course is the ultimate guide to conquer placements. Trusted by over 100,000+ geeks, this course is your roadmap to interview triumph.
Ready to dive in? Explore our Free Demo Content and join our Complete Interview Preparation course.

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 13 Aug, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads