SQL Aggregate Functions

These Aggregate functions are used in SQL to do operation on the values of the columns and it returns a single value for the respective column. These Functions are built-in SQL and are used for doing different operations in SQL. Let’s discuss some of the aggregate functions of SQL.

  1. AVG()
  2. SUM()
  3. COUNT()

Demo Table –

Product Table

Category City Country/Region Customer_ID Customer_Name Sales
Office Supplies Chicago United States SM-20950 Suzanne McNair 15.696
Technology New York City United States AH-10465 Amy Hunt 539.97
Office Supplies New York City United States AH-10465 Amy Hunt 22.58
Office Supplies Dover United States EP-13915 Emily Phan 16.52
Office Supplies Dover United States EP-13915 Emily Phan 671.94
Technology Aurora United States TP-21565 Tracy Poddar 169.064
Office Supplies Aurora United States TP-21565 Tracy Poddar 168.624
Office Supplies Long Beach United States AR-10825 Anthony Rawles 19.44
Office Supplies Pasadena United States HA-14920 Helen Andreada 31.92
Furniture Pasadena United States HA-14920 Helen Andreada 433.568

AVG() – This function returns the average of the values from the numeric column of the table.

  • SYNTAX –

SELECT AVG(column_name) FROM table_name ;

Example – Consider the above Sales Order table of the Customer database and calculate the average Sales.

SELECT AVG(Sales) AS Average_sales FROM [dbo].[Products];

 

Output :

Average_sales
227.547045056122

SUM() – This function returns the sum of the values from the numeric column of the table.

  • SYNTAX –

SELECT SUM(column_name) FROM table_name ;

Example – Consider the above Sales Order table of the Customer database and calculate the Sum of Sales.

SELECT SUM(Sales) AS sumofsales FROM [dbo].[Products];

 

Output:

sumofsales
1905478.95529997

COUNT() – This function returns the count of the values from the column of the table.

  • SYNTAX –

SELECT COUNT(column_name) FROM table_name ;

Example – Consider the above Sales Order table of the Customer database and calculate the count of the total orders.

SELECT COUNT([Order ID]) AS Total_orders FROM [dbo].[Products];

 

Output :

Total_orders
10

Follow us on TwitterFacebookLinkedin, and Tableau Public to stay updated with our latest blog and what’s new in Tableau.

Automate data analysis pipeline and create report ready dashboards

If you are looking forward to getting your data pipeline built and setting up the dashboard for business intelligence, book a call now from here.

#analytics #data #business #artificialintelligence #machinelearning #startup #deeplearning #deeplearning #datascience #ai #growth #dataanalytics #india #datascientist #powerbi #dataanalysis #tableau #SQL #businessanalytics #businessanalyst #businessandmanagement #dataanalyst #businessanalysis #analyst #analysis #powerbideveloper #powerbidesktop #letsviz