Write a query to practice in Northwind database

 1. WAQ to display average price for all beverages products?  

select AVG(isnull(p.unitprice,0)) as "avg product price" from dbo.Products P

          join dbo.Suppliers s on s.SupplierID=P.SupplierID

  join dbo.Categories c on c.CategoryID=p.CategoryID

  where CategoryName='Beverages'

2. WAQ to display unique titles in the employee table?     

   SELECT distinct e.Title  FROM [dbo].[Employees] AS  e


3. WAQ to display Total Sales for each customer in October 1996 (based on OrderDate).  

    Show the result in CustomerID, CompanyName, and total sales, sorted in total sales in Decending order 


    select * from [dbo].[Customers] where CustomerID='SPLIR'

select * from [dbo].[Orders] where CustomerID='SPLIR'

select * from [dbo].[Order Details] where orderID in ( select orderID from [dbo].[Orders] where CustomerID='SPLIR')


select cm.CustomerID,cm.CompanyName, (UnitPrice *Quantity) - (Discount*UnitPrice*Quantity) as "total sales" from  [dbo].[Customers] cm

           JOIN [dbo].[Orders] o ON cm.CustomerID=o.CustomerID

           JOIN [dbo].[Order Details] od ON od.OrderID=o.OrderID

   where Year(o.OrderDate)=1996 and Month(o.OrderDate)=10

   order by "total sales" desc

Comments

Popular posts from this blog

How to write an email for last day in office