blog post

SELECT COUNT returns a count of the number of data values.
SELECT SUM returns the sum of the data values.
SELECT AVG returns the average of the data values.

The SQL SELECT COUNT, SUM, and AVG syntax

The general COUNT syntax is:
SELECT COUNT(column-name)
  FROM table-name
The general SUM syntax is:
SELECT SUM(column-name)
  FROM table-name
The general AVG syntax is:
SELECT AVG(column-name)
  FROM table-name

SQL SELECT COUNT, SUM, and AVG Examples

Problem: Find the number of customers
SELECT COUNT(Id)
  FROM Customer

Problem: Compute the total amount sold in 2016
SELECT SUM(TotalAmount)
  FROM [Order]
 WHERE YEAR(OrderDate) = 2016

Problem: Compute the average size of all orders
SELECT AVG(TotalAmount)
  FROM [Order]

  • Share This Story


Pleas give your valuable comments to improve the contents.

about author

Atul kumar shukla


I'm Atul Kumar Shukla, working as a web developer.
Welcome to my Blog. This is my personal blog where i post my own questions and answers , articles about ASP.Net., SQL Server, HTML, CSS, Jquery and many more..

Visit Profile

Leave a comment

Name
E-mail
Url
Message

Get More Stuff
Subscribing to the TheOneblogs newsletter and get intersting stuff and updates to your email inbox.
Your Email

 

Style Switcher

Change Color

×! We use cookies to improve your user experience. More information