The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 2 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
 /*************************  EXAMPLE AND INSTRUCTIONS ********************  NORTHWIND
Using the example below based on a dummy table and its values and after watching the video on aggregates answer the following questions (Each question carries equal points of 10 points each):
Various Aggregate Functions
1) Count()
2) Sum()
3) Avg()
4) Min()
5) Max()
Â
Now let us understand each Aggregate function with a example:
Id   Name   Salary
-----------------------
1 Â Â Â A Â Â Â Â 80
2 Â Â Â B Â Â Â Â 40
3 Â Â Â C Â Â Â Â 60
4 Â Â Â D Â Â Â Â 70
5 Â Â Â E Â Â Â Â 60
6 Â Â Â F Â Â Â Â Null
Â
Count():
Â
Count(*): Returns total number of records .i.e 6.
Count(salary): Return number of Non Null values over the column salary. i.e 5.
Count(Distinct Salary): Â Return number of distinct Non Null values over the column salary .i.e 4
Â
Sum():
Â
sum(salary): Â Sum all Non Null values of Column salary i.e., 310
sum(Distinct salary): Sum of all distinct Non-Null values i.e., 250.
Â
Avg():
Â
Avg(salary) = Sum(salary) / count(salary) = 310/5
Avg(Distinct salary) = sum(Distinct salary) / Count(Distinct Salary) = 250/4
Â
Min():
Â
Min(salary): Minimum value in the salary column except NULL i.e., 40.
Max(salary): Maximum value in the salary i.e., 80.
Â
***********************************************/
Â
/* Question 1: Select the total number of Products in the Products table */
/* Question 2: Select the total number of Shippers for Orders (Hint: use COUNT(ShipVia) as TotalProducts to return non-null counts. */
/* Question 3: Select the total number of DISTINCT Shippers for Orders */
/* Question 4: Select all non-null total price from Order Details where OrderID = 10248 */
/* Question 5: Select all non-null distinct non-null freight charges from the Orders table */
/* Question 6: Select all non-null distinct total products that were ordered from the Order Details table */
/* Question 7: Select average unitprice of Products */
/* Question 8: Select ProductName and UnitPrice pf Products that have an above average price:Â
(Hint: Use a sub-query similar to one done during class exercise to first write sub-query to select Average UnitPrice of Products and
then using a where clause (UnitPrice > (subquery)) as part of the outer query select ProductName and UnitPrice)
*/
/*Â
Question 9a: Select Product having the maximum UnitPriceÂ
Question 9b: Select Product having the minimum UnitPrice
*/
/* Question 10: Select CompanyName, count(OrderID) as NumberOfOrders grouped by shippers
*/