You are on page 1of 12

Assignment 05

1. List the customers who live on Main Street (in any city).

Results:

SQL SELECT Customers.Name, Customers.Street FROM Customers WHERE (((Customers.Street) Like "*Main *"));

2. List the customers who have an account balance between $300 and $500, sorted by account balance in descending order.

Results:

SQL SELECT Customers.Name, Customers.AccountBalance FROM Customers WHERE (((Customers.AccountBalance)>=300 And (Customers.AccountBalance)<=500));

3. What is the total amount of money owed us by customers who live in Miami?

Results:

SQL SELECT Customers.Name, Customers.City, Customers.AccountBalance FROM Customers WHERE (((Customers.City)="Miami"));

4. How many orders have been placed by customers from Seattle after April?

Results:

SQL SELECT Count(Orders.ODate) AS CountOfODate, Customers.City FROM Customers INNER JOIN Orders ON Customers.CID = Orders.CID GROUP BY Customers.City HAVING (((Count(Orders.ODate))>4/1/2004) AND ((Customers.City)="Seattle"));

5. What is the largest order ever placed (in terms of amount)? New query in design view menu

Results:

SQL view: SELECT Max(Orders.Amount) AS MaxOfAmount FROM Orders;

6. Which item (Item ID and Description) had the most sales in terms of quantity?

Results:

SQL: SELECT TOP 1 ItemsSold.ItemID AS Items_ItemID, Items.Description, Sum(ItemsSold.Quantity) AS Quantitytotal FROM Items INNER JOIN ItemsSold ON Items.[ItemID] = ItemsSold.[ItemID] GROUP BY ItemsSold.ItemID, Items.Description ORDER BY Sum(ItemsSold.Quantity) DESC;

7. What was the best day in terms of highest total value of orders?

Results:

SQL: SELECT TOP 1 Orders.ODate, Sum(Orders.Amount) AS Totalvalue FROM Orders GROUP BY Orders.ODate ORDER BY Sum(Orders.Amount) DESC;

8. Calculate the total commissions owed to salesperson Johnson. Hint: You need to compute the total of commission multiplied by order amount.

Results:

SQL: SELECT Salespeople.Name, Sum(Orders.Amount*Salespeople.Commission) AS TotalCommission FROM Salespeople INNER JOIN Orders ON Salespeople.[SID] = Orders.[SID] WHERE (((Salespeople.Name)='Johnson')) GROUP BY Salespeople.Name;

9. Get the name and phone number of customers who bought blue jeans in June 2004.

Results:

SQL: SELECT Customers.Name, Customers.Phone, Items.Description, Orders.ODate FROM Items INNER JOIN (Customers INNER JOIN (Orders INNER JOIN ItemsSold ON Orders.OrderID = ItemsSold.OrderID) ON Customers.CID = Orders.CID) ON Items.ItemID = ItemsSold.ItemID WHERE (((Items.Description) Like 'Blue jeans') AND ((Orders.ODate)<=#6/30/2004# And (Orders.ODate)>=#6/1/2004#));

10. List all of the items sold in May

Results:

SQL: SELECT Items.ItemID, Items.Category, Items.Description, Orders.ODate FROM Items INNER JOIN (Orders INNER JOIN ItemsSold ON Orders.OrderID = ItemsSold.OrderID) ON Items.ItemID = ItemsSold.ItemID WHERE (((Orders.ODate)<=#5/30/2004# And (Orders.ODate)>=#5/1/2004#));

11. Which salesperson sold jeans to a customer in Phoenix?

Results:

SQL: SELECT DISTINCT Salespeople.Name, Salespeople.SID, Customers.City, Items.Description FROM Salespeople, Customers, Items, ItemsSold, Orders WHERE (((Salespeople.SID)=[Orders].[SID]) AND ((Customers.City)='Phoenix') AND ((Items.Description) Like '*jeans*') AND ((Orders.CID)=[Customers].[CID]) AND ((Orders.OrderID)=[ItemsSold].[OrderID]) AND ((ItemsSold.ItemID)=[Items].[ItemID]));

12. Create an input screen that enables a clerk to update information and add new customers to the database.

You might also like