Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

SQL - 04

The document outlines SQL concepts including aliases and aggregate functions. It provides examples of various aggregate functions such as COUNT, SUM, AVG, MAX, and MIN, along with exercises related to a Sales table to apply these functions. The exercises involve calculating total revenue, product counts, average prices, and other metrics using SQL queries.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

SQL - 04

The document outlines SQL concepts including aliases and aggregate functions. It provides examples of various aggregate functions such as COUNT, SUM, AVG, MAX, and MIN, along with exercises related to a Sales table to apply these functions. The exercises involve calculating total revenue, product counts, average prices, and other metrics using SQL queries.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Outline

 SQL Aliases
 SQL Aggregate Functions
SQL Aliases
Syntax : SQL Aliases
Example : SQL Aliases
Example : SQL Aliases
SQL Functions
SQL : Aggregate Function
Count Function
Example : Count Function
SUM () Function
AVG () Function
MAX() Function
MIN() Function
Exercise – Aggregate Functions
Let's assume the table is called Sales with the following columns:
SalesID (Primary Key)
Product (VARCHAR)
Category (VARCHAR)
Quantity (INT)
Price (DECIMAL)
SaleDate (DATE)
Exercise – Aggregate Functions
1. What is the total revenue generated?(Use SUM(Quantity * Price))
2. How many products have been sold in total?(Use SUM(Quantity))
3. What is the average price of products?(Use AVG(Price))
4. How many unique product categories exist?(Use COUNT(DISTINCT Category))
5. What is the highest price of a product in the table?(Use MAX(Price))
6. What is the lowest price of a product in the table?(Use MIN(Price))
7. What is the average quantity sold per transaction?(Use AVG(Quantity))
8. How many total sales records are there in the table?(Use COUNT(SalesID) or COUNT(*))
9. What is the total revenue for each product category?(Use SUM(Quantity * Price) grouped by Category)
10. What is the average price of products in each category?(Use AVG(Price) grouped by Category)
11. Which category has the highest total revenue?(Use SUM(Quantity * Price) with GROUP BY and ORDER
BY DESC)
12. What is the total quantity sold for each product?(Use SUM(Quantity) grouped by Product)
13. What is the maximum quantity sold in a single transaction?(Use MAX(Quantity))
14. What is the total revenue for a specific product, e.g., "Laptop"?(Use SUM(Quantity * Price) with a
WHERE Product = 'Laptop')
Thank You

You might also like