0% found this document useful (0 votes)
281 views7 pages

Workshop Question

This document provides instructions for querying an AdventureWorks database across 5 days. It includes 52 individual queries to write covering topics like displaying customer, order, product and sales data; filtering results; aggregating data; joining tables; and formatting output. The goal is to gain experience with the SQL syntax needed to extract and manipulate data from a sample database.

Uploaded by

KarthikJatti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
281 views7 pages

Workshop Question

This document provides instructions for querying an AdventureWorks database across 5 days. It includes 52 individual queries to write covering topics like displaying customer, order, product and sales data; filtering results; aggregating data; joining tables; and formatting output. The goal is to gain experience with the SQL syntax needed to extract and manipulate data from a sample database.

Uploaded by

KarthikJatti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Pre-Requisites:

 AdventureWorks database in OTBSQLSERVER; Use Windows Authentication to connect

Day 2
1. Display the details of all the Customers.

2. Display the ID, type, number, and expiry year of all the credit cards in the
following format.

Credit Card ID Credit Card Type Credit Card Number Expiry Year

3. Display the customer ID and the account number of all the customers who
live in the Territory ID 4.
4. Display all the details of the sales orders that have a cost exceeding $2,000.
5. Display the sales order details of the product named 'Cable Lock'. Hint: The
Product ID for Cable Lock is 843.

6. Display the list of all the orders placed on June 06, 2004.
7. Display a report of all the orders in the following format.

Order Id Order Quantity Unit Price Total Cost

Hint: Total Cost = Order Quantity * Unit Price

8. Display a list of all the sales orders in the price range of $2,000 to $2,100.
9. Display the name, country region code, and sales year to date for the territory
with Territory ID as 1.
10. Display the details of the orders that have a tax amount of more than $10,000.
11. Display the sales territory details of Canada, France, and Germany.
12. Generate a report that contains the IDs of sales persons living in the territory
with Territory ID as 2 OR 4. The report is required in the following format.

Sales Person ID Territory ID

13. Display the details of the Vista credit cards that are expiring in the year
2006.
14. Display the details of all the orders that were shipped after July 12, 2004.
15. Write a query to display the sales order ID, territory ID, month, and year of
order in the following format.

Sales Order ID Territory Name Month Year

Day 3
16. Display the orders placed on July 01, 2001 that have a total cost of more
than $10,000 in the following format.

Order Number Order Date Status Total Cost

17. Display the details of the orders that have been placed by customers online.
18. Display the order ID and the total amount due of all the sales orders in the
following format. Ensure that the order with the highest price is at the top of the
list.

Order Date Total Due

19. Display the order ID and the tax amount for the sales orders that are less
than $2,000. The data should be displayed in the ascending order.
20. Display the order number and the total value of the order in ascending
order of the total value.
21. Display the maximum, minimum, and the average rate of sales orders.
22. Display the total value of all the orders put together.
23. Display the Order ID of the top five orders based on the total amount due in
the year 2001.
24. Display the details of all the currencies that have the word 'Dollar' in their
name.
25. Display all territories whose names begin with 'N'.
26. Display the SalesPersonID, the TerritoryID, and the sales quota for those
sales persons who have been assigned a sales quota. The data should be
displayed in the following format.

Sales Person Territory ID Sales Quota


ID
27. What will be the output of the following code written to display the total
order value for each order?

SELECT SalesOrderID, ProductID, sum (LineTotal) FROM


Sales.SalesOrderDetail GROUP BY SalesOrderID

28. You can place an order for more than one product. Display a report
containing the product ID and the total cost of products for the product ID whose
total cost is more than $10000.
29. The following SQL query containing the COMPUTE BY clause generates
errors. What are possible causes of such errors?
SELECT ProductID, LineTotal AS 'Total' FROM Sales.SalesOrderDetail
COMPUTE sum (LineTotal) BY ProductID.

Day 4

30. Display the top three sales persons based on the (highest) bonus.
31. Display the details of those stores, which have Bike in their name.
32. Display the total amount collected from the orders for eachby order
date.
33. Display the total unit price and the total amount collected after
selling the products, 774 and 777. In addition, calculate the total amount
collected from these two products.
34. Display the sales order ID and the maximum and minimum values of
the order based on the sales order ID. In addition, ensure that the order
amount is greater than $5,000.
35. A report containing the sales order ID and the average value of the
total amount, which is greater than $5,000, is required in the following format.

Sales Order ID Average Value

36. Display the different types of credit cards used for purchasing
products.
37. Display the customer ID, name, and sales person ID for all the
stores. According to the requirement, only first 15 letters of the customer name
should be displayed.

38. Display all orders in the following format.

Order Number Total due Day Of Order Week Days


39. Display SalesOrderID, OrderQty, and UnitPrice from the SalesOrderDetail
table where a similar unit price needs to be marked with an identical value.
40. Display the EmployeeID and the HireDate of the employees from the
Employee table. The month and the year need to be displayed.
41. Write a query to find all the people in the Person.Contact table with three-
letter last names ending with ‘an’.
42. Write a query to calculate the average vacation hours and the sum of sick
leave hours of the employees who work as Production Technician.
43. Write a query to find the number of different titles that an employee who
works at AdventureWorks can hold.
44. Write a query to display all the sales persons and name of the territories to
which they belong.
45. Write a query to display the sales order ID, the product ID, and order date for
all products in the following format.

Order ID Product ID Order Date

46. Write a query to display the sales person ID and territory names for all sales
persons. If a sales person does not belong to any territory, NULL should be
displayed.

Sales Person Territory


ID Name
268 NULL
275 Northeast

47. Write a query to display the total amount due of all the sales orders rounded
off to a whole number. In addition, display the sales order ID and the type of
credit card through which the payment was made.
48. Write a query to display the order date along with the sales order ID and
territory name. The order date should be displayed in the dd/mm/yyyy format.
49. Write a query to display the order ID and the territory name of the orders
where the month of order is May and year is 2004.
50. Write a query to retrieve the details of the product locations where cost rate is
greater than 12. In addition, the locations need to be grouped into three groups,
and then ranked based on the cost rate in descending order.
51. Display all female employee names and their manager name. Even if an
employee does not have a manger, those employee name should appear in the
result
52. Display all single male employees and their address (including state name,
country name) who wereborn before the year : 1980
53. Which manager (name) has the most number of employees working under
him/her?
54. Which manager (name) has the most number of female employees working
under him/her?
55. Display the number of employees by each state (state name) – based on their
address.
56. Find the second highest salaried employee per their current rate. Hint: Use
CTE for finding the latest rate per employee
57. Display the following details assuming all employees worked 7 days a week
and 8 hrs per day:Employee ID, Employee Name, Total Salary drawn till date.
Hint : Use CTE / Correlated sub query

Day 5

58. Create a table as ProductMaster as follows.


a. ProductID auto increament from 200 onwards.
b. ProductName string type max 20.
c. QtyinStock integer type default 1.
d. ProductPrice numeric
e. AvailableCity string type max 20 and should be only in these cities
Chicago, California, Detroit,Washington.

53. Create a table as SalesMaster as follows.


a. ProductID set as Foreign Key
b. SalesID primary key numeric
c. Orderdate date datatype
d. City string type
e. issuedate date datatype

59. . Alter the above table and add these features.


a. Add a new column as ProductDescription string type.
b. Rename the column as AvailableRegion from AvailableCity .

60. Create a view which displays Employee names and addresses with
following columns

o EmployeeID
o Title
o FirstName
o MiddleName
o LastName
o Suffix
o JobTitle
o Phone
o EmailAddress
o EmailPromotion
o AddressLine1
o AddressLine2
o City
o StateProvinceName
o PostalCode
o CountryRegionName
o AdditionalContactInfo

61. Create a view which displays employee name, title, and current department
and other columns as below
o EmployeeID
o Title
o FirstName
o MiddleName
o LastName
o Suffix
o JobTitle
o Department Name
o GroupName Name
o StartDate

62. Create a batch that finds the average pay rate (latest) of the employees
and then lists the details of employees who have a pay rate less than the
average pay rate.
63. Create a batch that displays all the employee details where for the ‘Marital
Status’ column it should display “Married’ for ‘M’ and ‘Single’ for ‘S’ and others
as ‘Unknown’.

Day 6
64. Create a function that returns the shipment date of a particular order.
65. Create a function that returns the credit card number for a particular order.
66. Create a function that returns a table containing the ID and the name of the
customers who are categorized as individual customers (CustomerType = 'I').
The function will take one parameter. The parameter value can be either
Shortname or Longname. If the parameter value is Shortname, only the last
name of the customer will be retrieved. If the value is Longname, then the full
name will be retrieved.
67. Write a procedure to display all the employee details along with the
department details to they belong based on the employee designation entered
by the user.

Day 7

68. Using serializable isolation level, write a query to display AddressTypeID


and Name where AddressTypeID is between 1 and 6
69. Write a batch query to update the email id as [email protected] in the
Person.Contact table for the employee with contact id 1080 and update the
address id =32456 in the HumanResources.EmployeeAddress table for
employee with EmployeeID 1 and during the update you need to ensure that
both the update statements should execute successfully or none of them
should execute. In addition if during the update operation any error comes then
the complete batch should be cancelled and when this transaction is going on
no other users should be allowed to perform any operation against the above
tables not even read should be allowed.

70. Write a query that deletes a job candidate whose ID is 13.

71. Set Transaction level isolation to snapshot and begin the transaction. Update the column
“ModifiedDate” to today’s date.

72. The management of AdventureWorks, Inc. has decided that no user should
be able to change the prices of the products. In addition, management wants
that all the attempts to change the price should be saved in a temporary table,
Temp. John, the database developer has been asked to make the significant
changes in the database to implement this policy. What can John do to
achieve the same?
73. The management of AdventureWorks, Inc. wants that whenever the pay
rate of an employee is modified, its effect on the monthly salary of the
employee should be displayed. John, a database developer at
AdventureWorks, has been asked to resolve this problem. Help John to find
out appropriate solution.

74. Write a trigger to display the magic tables (Inserted and Deleted) data
during a trigger execution.
75. Write a query to retrieve the list price of the products where the product
price is between $ 360.00 and $ 499.00 and display the price in the following
format. The list price of “Product Name” is “Price”

You might also like