0% found this document useful (0 votes)
6 views

Assignment SQL 2

The document contains a series of SQL queries related to customer orders and product details. It includes aggregations such as counting orders by customer, summing quantities and revenues, and filtering results based on conditions like average price and order counts. The queries also involve grouping and ordering results to analyze sales data effectively.

Uploaded by

superfilo98i
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Assignment SQL 2

The document contains a series of SQL queries related to customer orders and product details. It includes aggregations such as counting orders by customer, summing quantities and revenues, and filtering results based on conditions like average price and order counts. The queries also involve grouping and ordering results to analyze sales data effectively.

Uploaded by

superfilo98i
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Question 1

select customerid, count(*) as totalorders from orders


group by customerid

Question 2

select orderid, sum(quantity) as totalquantity, avg(unitprice) as avgprice


from orderdetails
group by orderid
Question 3

select customerid, count(*) as totalorders from orders


group by customerid
order by totalorders desc
limit 5

Question 4

select customerid, count(*) as totalorders from orders


group by customerid
having count(*) > 5
Question 5

select productid, sum(unitprice*quantity) as revenue from orderdetails


group by productid

Question 6

select productid, round(avg(unitprice)) as avgprice from orderdetails


group by productid
having avg(unitprice) > 50
Question 7

select productid, max(unitprice) as maxprice from orderdetails


group by productid

Question 8

select employeeid, count(distinct (customerid)) as


number_of_customers_in_97 from orders
where orderdate between '1997-01-01' and '1997-12-31'
group by employeeid
order by employeeid

You might also like