• Home
  • SQL COUNT(), AVG() and SUM() Functions

    In SQL, you can use the COUNT, AVG, and SUM functions to perform calculations on your data. Here's a brief explanation of each function:


    1. COUNT: The COUNT function is used to count the number of rows that match a specific condition or that have non-null values in a particular column.

    Example:

    SELECT COUNT(*) AS TotalRows
    FROM table_name;

    This query will return the total number of rows in the specified table.


    2. AVG: The AVG function calculates the average value of a numeric column in a table.

    Example:

    SELECT AVG(column_name) AS AverageValue
    FROM table_name;

    This query will return the average value of the specified column in the table.


    3. SUM: The SUM function calculates the sum of numeric values in a column.

    Example:

    SELECT SUM(column_name) AS TotalSum
    FROM table_name;

    This query will return the sum of the values in the specified column.


    Note: In the above examples, replace "table_name" with the actual name of your table, and "column_name" with the name of the column you want to perform calculations on.


    You can also combine these functions with other clauses, such as WHERE, GROUP BY, and HAVING, to perform calculations on specific subsets of data or based on certain conditions.



    About the Author



    Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

    We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





     PreviousNext