0% found this document useful (0 votes)
8 views1 page

SQL Queries for Sales Data Analysis

The document contains SQL query examples for retrieving data from a database. Example 25.1 selects employee details from departments for the year 2017, while Examples 25.2 and 25.3 aggregate sales data by month and product for the years specified. Each example demonstrates different SQL functionalities such as JOINs, GROUP BY, and ORDER BY clauses.

Uploaded by

riyasathsafran
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

SQL Queries for Sales Data Analysis

The document contains SQL query examples for retrieving data from a database. Example 25.1 selects employee details from departments for the year 2017, while Examples 25.2 and 25.3 aggregate sales data by month and product for the years specified. Each example demonstrates different SQL functionalities such as JOINs, GROUP BY, and ORDER BY clauses.

Uploaded by

riyasathsafran
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Example 25.

SELECT dept_name, emp_lname, emp_fname, job, enter_date


FROM department d JOIN employee e ON d.dept_no = e.dept_no
JOIN works_on w ON w.emp_no = e.emp_no
WHERE YEAR(enter_date) = 2017
ORDER BY dept_name;

Example 25.2

SELECT [Link] AS month, [Link] AS year,


[Link] AS product_id, SUM([Link]) AS sum_of_sales,
COUNT([Link]) AS total_sales
FROM DimDate t, DimProduct p, FactInternetSales f
WHERE [Link] = [Link] AND [Link] = [Link]
AND CalendarYear = @year
GROUP BY [Link], [Link], [Link]
ORDER BY 1;

Example 25.3

SELECT [Link] AS month, [Link] AS year,


[Link] AS product_id, SUM([Link]) AS sum_of_sales,
COUNT([Link]) AS total_sales
FROM DimDate t, DimProduct p, FactInternetSales f
WHERE [Link]=[Link] AND [Link]=[Link]
AND CalendarYear = 2013
GROUP BY [Link],[Link],[Link]
ORDER BY 1;

You might also like