SQL Count, Avg, Sum

SQL Count, Avg, Sum

For example, let’s say we have a table called “sales” with the following columns:

  • id (unique identifier for each sale)
  • product (name of the product sold)
  • quantity (number of items sold)
  • price (price per item)
  • date (date of the sale)

Now, let’s explore some common scenarios using the COUNT, AVG, and SUM functions.

  1. Count the total number of sales:
sql
SELECT COUNT(*) AS total_sales
FROM sales;
  1. Calculate the average price of all products sold:
sql
SELECT AVG(price) AS average_price
FROM sales;
  1. Calculate the total quantity of items sold:
sql
SELECT SUM(quantity) AS total_quantity
FROM sales;
  1. Calculate the total sales revenue:
sql
SELECT SUM(quantity * price) AS total_revenue
FROM sales;
  1. Count the number of sales for a specific product (e.g., “Product A”):
sql
SELECT COUNT(*) AS sales_count
FROM sales
WHERE product = 'Product A';
  1. Calculate the average price of a specific product (e.g., “Product B”):
sql
SELECT AVG(price) AS average_price
FROM sales
WHERE product = 'Product B';

These are just a few examples of how you can use the COUNT, AVG, and SUM functions in SQL queries. Let me know if you have any other specific requirements or if you need assistance with a different scenario!

Posted in SQL

Leave a Reply

Your email address will not be published. Required fields are marked *

GLOTRU Footer
Popular Features
Popular Services/

Website Development & Design

App Development & Design

Graphic Design

Digital Marketing

SEO (Search Engine Optimization)

SMM (Social Media Marketing)

Cyber Security

Company

GLOTRU Founder & CEO : __Azam

Registared : Trade,MSME,etc

Board of Director

Team

About Us

Contact Us

Privacy Policy

Return & Refund Policy

Abuse Policy

Copyright Policy

Cookie Policy

Terms & Conditions

Universal Terms of Service

Disclaimer

Legal

Sponsorships

Investor

Press Releases

Our Investments

Brands

Newsroom

Business

...

_

Digital Millennium Copyright Act
DMCA.com Protection Status

_

Content similarity detection
Protected by Copyscape

_

***ANTI-PIRACY WARNING***

...................................................................................

Follow Us :

...................................................................................

SECURE SERVER : [Legal] [Privacy Policy] [Universal Terms of Service] [Do not sell my personal information]

SITE HOSTED : GLOTRU SECURE SERVER Asian Data Centre [You can host your site][Click Here]

SSL : Server Type : [Cloudflare] Certificate Issued By : [Let's Encrypt] Signature Algorithm : [ECDSA with SHA-384]

SITE BUILD SOFTWARE : Content Management System (CMS) Softwere

_

_

_