Lab Manual Week 04
Lab Manual Week 04
Lab Manual 4
Instructor:
• Mr. Nazeef Ul Haq and Mr. Nauman Babar
Learning Objectives:
• Understanding of Group functions, Having clause, Column and Table Alias.
Helping Material:
1. AGGREGATE FUNCTIONS:
Aggregate functions allow you to perform a calculation on a set of values to return a single scalar value. The
most common aggregate functions are:
• AVG
• MIN
• SUM
• COUNT
• STDEV
• STDEVP
• VAR
• VARP
• MAX
Note: All the Group function except COUNT ignore null values
Page 1 of 4
GROUP BY Title
HAVING COUNT(*) >1
Lab Tasks:
• Perform all the group function on Northwind Schema.
• Perform all the group function using HAVING clause on Northwind Schema
• Apply aliasing syntax on arbitrary column on Northwind Schema.
• Bonus: Find an alternate method to alias tables and columns in SQL Server.
Home Tasks:
All the given tasks should be performed in the context of Northwind Schema.
1. List name of all the products whose price is above average. (Product Name)
2. Write a query to generate report showing date wise orders shipped. (ShippedDate, numberoforders)
3. List name of all countries from where two or more suppliers belong to. (Country)
4. Write a query to generate report showing month wise orders delayed shipped. Your output should look
like this (Month Number, Orders Delayed)
Month Number Orders Delayed
1 75
2 75
. .
. .
. .
12 55
5. Report all the orders which have been discounted. Your result should show the total discount against each
order. Output should look like this (Order ID, Discount)
OrderID Discount
10250 0.300000011920929
10251 0.100000001490116
Page 2 of 4
10252 0.100000001490116
. .
. .
. .
6. Write a query to list the number of orders which were shipped in the cities of USA in 1997. Show the
number of order against each city. (Ship City, Number of orders)
7. Write a query to generate report showing country wise orders delayed shipped. Your output should look
like this: (Country, Orders Delayes)
8. Report all the orders which have been discounted with total price of order. Your result should show the
total discount against each order. Output should look like this: (Order ID, Discount, Total Price)
9. Write a query to list the number of orders which were shipped in the cities of each region in 1997. Show
the number of order against each city. Your results should look like this: (ShipRegion, ShipCity,
Numberoforders)
HackerRank Tasks:
1. https://www.hackerrank.com/challenges/average-population/problem?isFullScreen=true
2. https://www.hackerrank.com/challenges/revising-aggregations-the-average-
function/problem?isFullScreen=true
3. https://www.hackerrank.com/challenges/revising-aggregations-sum/problem?isFullScreen=true
4. https://www.hackerrank.com/challenges/revising-aggregations-the-count-
function/problem?isFullScreen=true
5. https://www.hackerrank.com/challenges/weather-observation-station-6/problem?isFullScreen=true
6. https://www.hackerrank.com/challenges/weather-observation-station-7/problem?isFullScreen=true
Page 3 of 4
7. https://www.hackerrank.com/challenges/weather-observation-station-8/problem?isFullScreen=true
8. https://www.hackerrank.com/challenges/weather-observation-station-9/problem?isFullScreen=true
9. https://www.hackerrank.com/challenges/weather-observation-station-10/problem?isFullScreen=true
10. https://www.hackerrank.com/challenges/weather-observation-station-11/problem?isFullScreen=true
11. https://www.hackerrank.com/challenges/weather-observation-station-12/problem?isFullScreen=true
12. https://www.hackerrank.com/challenges/more-than-75-marks/problem?isFullScreen=true
13. https://www.hackerrank.com/challenges/population-density-difference/problem?isFullScreen=true
14. https://www.hackerrank.com/challenges/the-blunder/problem?isFullScreen=true
15. https://www.hackerrank.com/challenges/earnings-of-employees/problem?isFullScreen=true
16. https://www.hackerrank.com/challenges/what-type-of-triangle/problem?isFullScreen=true
17. https://www.hackerrank.com/challenges/what-type-of-triangle/problem?isFullScreen=true
What to Submit:
You are required to submit the following files.
• .SQL File
• Notepad File
• Pdf report.
Page 4 of 4