Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Prepare and execute each of the queries listed using the \"Adventureworks2012\"

ID: 3764531 • Letter: P

Question

Prepare and execute each of the queries listed using the "Adventureworks2012" database in SQL:

Server.http://msftdbprodsamples.codeplex.com/releases/view/93587

When all of your queries are complete, cut and paste the SQL Syntax into a word document. In order to see what the column names are, you need to click on the table and then Columns to see the field names. Make sure to include column headings that make sense in the queries (use the as “Field Name” after the field selected).

Multi-table Queries (each query will require the access of at least 2 tables, maybe more):

1. Write a query to find all of the employees that work for Research and Development group, that have a start date after 01-01-2005. List their DepartmentID, StartDate, Department Name, and GroupName. Order by StartDate. You will need to use HumanResources.Department, and HumanResources.EmployeeDepartmentHistory tables for this query. You should get 4 records total.

2. Write a query to find the sales people that earned a bonus over $3,700. List the salespersons title, first name, last name, bonus and commission percentage. Order by bonus descending. You will need to use the Sales.SalesPerson and Person.Person tables. You should get 7 records.

3. Write a query to find out the number of female employees that make over $10 per hour (rate). List their job title, Gender, Marital Status, Hire Date, and Rate. Sort by rate and marital status. Use HumanResources.Employee and HumanResources.EmployeePayHistory. You should get 73 records.

4. Write a query to find out what sales people have a sales quota over 250,000 and are in territory 5. List the Business Entity ID, Territory ID, Sales Quota, Sales YTD, Sales Last Year, Customer ID, and Stored ID. Sort by customer id. Use Sales.SalesPerson and Sales.Customer tables. You should get 176 records.

5. Write a query to find out how many products had a scrapped quantity greater than 20. List the Product ID, Product Name, Product Number, Work Order ID, Order Quantity, Scrapped Quantity, and Scrap Reason ID. Sort by Scrapped Quantity, and then by Product ID. You should get 95 records.

6. Write a query to find out how many people have a Seattle address. List the Address ID, Address Lines (Street and Apt number if available), City, StateProvince ID, Name, and Business Entity ID. Use the Person.Address, Person.AddressType, and Person.BusinessEntityAddress tables. Sort by Address ID. You should get 141 records.

7. Write a query to find out the minimum order quantity greater than 100 for all vendors. List the vendor name, account number, credit rating, last receipt cost, maximum order quantity, and minimum order quantity. Soft by minimum order quantity and then by maximum order quantity. Use the Purchasing.ProductVendor and Purchasing.Vendor tables. You should get 38 records.

8. Write a query to find out how many Vista credit cards expire in 2008 or more recent (2009, 2010, etc.). List the Credit Card ID, Card Type, Card Number, Expiration Month, Expiration Year, Sales Order ID, and Customer ID. Sort by expiration year, and then expiration month. Use the Sales.Creditcard and Sales.SalesOrderHeader tables. You should get 1,708 records.

9. Write a query to find out how many Vista credit cards expire in 2008 or more recent (2009, 2010, etc.) from customer 11151, 11223, and 11750. List the Credit Card ID, Card Type, Card Number, Expiration Month, Expiration Year, Sales Order ID, and Customer ID. Order by Customer ID. Use the Sales.Creditcard and Sales.SalesOrderHeader tables. You should get 33 records.

10. Write a query to find out how many products had a scrapped quantity greater than 20 and an order quantity greater than 2000 . List the Product ID, Product Name, Product Number, Work Order ID, Order Quantity, Scrapped Quantity, and Scrap Reason ID. Sort by Scrapped Quantity, and then by Product ID. You should get 56 records.

Explanation / Answer

use AdventureWorks2012
/*Answer for 1*/
/*Replace e.* with e.name etc - question did not include what emp fields are required*/
select d.DepartmentID, h.StartDate, d.Name, d.GroupName,e.* from HumanResources.Employee as e
inner join HumanResources.EmployeeDepartmentHistory as h on h.BusinessEntityID = e.BusinessEntityID
inner join HumanResources.Department as d on d.DepartmentID=h.DepartmentID
Where d.GroupName = 'Research and Development' and h.StartDate > '20050101'
order by 2;
/*Date format for filtering is yyyymmdd*/

/*Answer for 2*/
select p.Title, p.FirstName, P.LastName, sp.Bonus, sp.CommissionPct from Person.Person as p
inner join sales.SalesPerson as sp on sp.BusinessEntityID = p.BusinessEntityID
where sp.Bonus>3700
order by 4 desc;


/*Answer for 3*/
select * from HumanResources.Employee as e
inner join HumanResources.EmployeePayHistory as p on p.BusinessEntityID= e.BusinessEntityID
where e.Gender='F' and p.Rate>10

/* Answer for 4
No rows are matching - please check your answer*/
select p.BusinessEntityID, c.TerritoryID, p.SalesQuota,p.SalesYTD,p.SalesLastYear,c.CustomerID,c.StoreID from Sales.SalesPerson as p
inner join Sales.Customer as c on c.PersonID = p.BusinessEntityID
where p.SalesQuota>250000 and   p.TerritoryID=5

/*Answer for 5*/
select w.ProductID, p.Name , p.ProductNumber, w.WorkOrderID, w.OrderQty, w.ScrappedQty, w.ScrapReasonID from Production.WorkOrder as w
left join Production.Product as p on p.ProductID= w.ProductID
where w.ScrappedQty>20

As per chegg guidelines there are too many sub questions - please post one more question asking for the remaining.