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

Lab2a Ans

This document contains 5 SQL queries to analyze sales data: 1) sums order amounts by country, 2) sums order amounts by salesperson from largest to smallest, 3) finds the top 5 salespersons by order amount, 4) finds the bottom 3 salespersons by order amount, 5) shows each salesperson's total amount and percentage of the grand total.

Uploaded by

Eunice Wong
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)
57 views1 page

Lab2a Ans

This document contains 5 SQL queries to analyze sales data: 1) sums order amounts by country, 2) sums order amounts by salesperson from largest to smallest, 3) finds the top 5 salespersons by order amount, 4) finds the bottom 3 salespersons by order amount, 5) shows each salesperson's total amount and percentage of the grand total.

Uploaded by

Eunice Wong
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
You are on page 1/ 1

A.

Comparing the sum of order amount for different countries

SELECT country, SUM ([order amount]) AS total_amount


FROM tbl_sales
GROUP BY country

B. Calculating the sum of order amount for each salesperson, and sorting the results from largest to smallest
sales

SELECT Salesperson, SUM ([order amount]) AS total_amount


FROM tbl_sales
GROUP BY Salesperson
ORDER BY total_amount DESC

C. Finding the five salespersons with the top five sales order amount

SELECT TOP (5) Salesperson, SUM([Order Amount]) AS total_amount


FROM tbl_sales
GROUP BY Salesperson
ORDER BY total_amount DESC

D. Finding the three salespersons with the bottom three sales order amount

SELECT TOP (3) Salesperson, SUM([Order Amount]) AS total_amount


FROM tbl_sales
GROUP BY Salesperson
ORDER BY total_amount ASC

E. Showing the total order amount for each salesperson, and calculating summarized order amounts as a
percentage of the grand total

SELECT Salesperson, SUM([Order Amount]) AS total_amount,


SUM ([Order Amount])/(SELECT SUM([Order Amount]) FROM tbl_sales)*100
FROM tbl_sales
GROUP BY Salesperson

You might also like