The document provides SQL queries for analyzing sales data from a 'Sales' table, focusing on aggregate functions. It includes queries to calculate total sales per product, sales counts, and sales totals by date and day of the week, with specific conditions for filtering results. The queries aim to identify products and dates with significant sales figures, enhancing understanding of sales performance.
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 ratings0% found this document useful (0 votes)
9 views5 pages
Master Aggregate Functions
The document provides SQL queries for analyzing sales data from a 'Sales' table, focusing on aggregate functions. It includes queries to calculate total sales per product, sales counts, and sales totals by date and day of the week, with specific conditions for filtering results. The queries aim to identify products and dates with significant sales figures, enhancing understanding of sales performance.
-- 1. Total Sales per Product - Products with total sales greater than $500 SELECT ProductName, SUM(SaleAmount) AS TotalSales FROM Sales GROUP BY ProductName HAVING SUM(SaleAmount) > 500;
-- 2. Total Sales per Product - Products with total
sales between $500 and $800 SELECT ProductName, SUM(SaleAmount) AS TotalSales FROM Sales GROUP BY ProductName HAVING SUM(SaleAmount) BETWEEN 500 AND 800;
-- 3. Total Sales per Product - Products with total
sales exactly $860 SELECT ProductName, SUM(SaleAmount) AS TotalSales FROM Sales GROUP BY ProductName HAVING SUM(SaleAmount) = 860;
Follow me on LinkedIn – Shivakiran kotur
-- 4. Number of Sales per Product - Products with more than 5 sales records SELECT ProductName, COUNT(*) AS NumberOfSales FROM Sales GROUP BY ProductName HAVING COUNT(*) > 5;
-- 5. Total Sales per Date - Dates with total sales
above $250 SELECT SaleDate, SUM(SaleAmount) AS TotalSales FROM Sales GROUP BY SaleDate HAVING SUM(SaleAmount) > 1000;
-- 6. Total Sales per Product - Products with total
sales less than $1000 and more than $700 SELECT ProductName, SUM(SaleAmount) AS TotalSales FROM Sales GROUP BY ProductName HAVING SUM(SaleAmount) < 1000 AND SUM(SaleAmount) > 700;
Follow me on LinkedIn – Shivakiran kotur
-- 7. Total Sales per Product - Products with exactly 4 sales records SELECT ProductName, COUNT(*) AS NumberOfSales, SUM(SaleAmount) AS TotalSales FROM Sales GROUP BY ProductName HAVING COUNT(*) = 4;
-- 8. Total Sales per Month - Months with total
sales greater than $1000 SELECT DATEPART(MONTH, SaleDate) AS SaleMonth, SUM(SaleAmount) AS TotalSales FROM Sales GROUP BY DATEPART(MONTH, SaleDate) HAVING SUM(SaleAmount) > 1000;
Follow me on LinkedIn – Shivakiran kotur
-- 9. Total Sales per Day of Week - Days of the week with total sales above $500 SELECT DATENAME(WEEKDAY, SaleDate) AS DayOfWeek, SUM(SaleAmount) AS TotalSales FROM Sales GROUP BY DATENAME(WEEKDAY, SaleDate) HAVING SUM(SaleAmount) > 500;
List of Key Financial Ratios: Formulas and Calculation Examples Defined for Different Types of Profitability Ratios and the Other Most Important Financial Ratios