Tables
-------Customers CustomerID, CustomerName, ContactName, Address, City,
Postalcode, Country
Categories - CategoryId, CategoryName, Description
Employees - EmployeeID, LastName, FirstName, BirthDate, Photo, Notes
Order Details - OrderDetailID, OrderID, ProductID, Quantity
Orders - OrderID, CustomerID, EmployeeID, OrderDate, ShipperID
Products - ProductID, ProductName, SupplierID, CategoryID, Unit, Price
Shippers - ShipperID, ShipperName, Phone
Suppliers - SupplierID, SupplierName, ContactName, Address, City,
PostalCode, Country, Phone
1) Get all the Customers and their Full Address details who placed orders more
than 25 in Quantity
Select C.CustomerID, C.CustomerName, C.ContactName, C.Address, C.City,
C.Postalcode, C.Country, O.OrderID
from Customers C, Orders O, Orderdetails OD
where C.CustomerID = O.CustomerID
and O.OrderID = OD.OrderID and OD.quantity > 25;
2) Get Top 5 costliest Product Details and their Supplier Names and Address along
with Phone number
Select top 5 (Price),ProductID, ProductName, SupplierName, Address, Phone from
Products P
inner join Suppliers S
on P.SupplierID = S.SupplierID;
3) Get me the Maximum and Minimum Product details in a single Query
Ans: Select ProductID, Max(price), Min(Price) from Products group by ProductID;
4) Get me the Total Orders list along with their Quantity for the Orders placed
between 09/01/1996 and 01/31/1997
Order Details - OrderDetailID, OrderID, ProductID, Quantity
Orders - OrderID, CustomerID, EmployeeID, OrderDate, ShipperID
Select O.OrderID, sum(OD.quantity) as TotQty ,count(O.OrderID) as totorders
from OrderDetails OD, Orders O
where OD.OrderID = O.OrderID
group by OD.OrderID having O.Orderdate between '09/01/1996' and '01/31/1997';
5) Give me the category descripton of all products which cost less than 10$
Select P.productID, P.ProductName, C.Description
From Products P inner join Categories C on P.CategoryID = C.CategoryID
And P.Price < 10
6) Get the Employee details who sold more products(In quantity). I want the
employee Names as "LastName-Firstname"
Employees - EmployeeID, LastName, FirstName, BirthDate, Photo, Notes
Order Details - OrderDetailID, OrderID, ProductID, Quantity
Orders - OrderID, CustomerID, EmployeeID, OrderDate, ShipperID
Select E.EmployeeID, E.LastName||-||E.FirstName as Empname, E.Birthdate ,
max(OD.quantity)
From Employees E, OrderDetails OD, Orders O
Where E.EmployeeID = O.EmployeeID
And O.OrderID = OD.OrderID
group by Empname, E.EmployeeID, E.Birthdate;
7) Give me the Phone number of the shipper who shipped more Quantity in the
month of 1996 December
There is no common column to Join
8) Get me Top 5 products which are ordered the most and also Top 5 products
whose total price is more in descending order
Select Top 5 ProductName, Price From Products
Order by desc;