Professional Documents
Culture Documents
Practice Questions
Practice Questions
We need an output which has the RateChangeDate column with only the date, full name (first name, middle name,
and last name) and weekly salary (given they work 40 hours a week). The hourly rates for each employee is given in
HumanResources.EmployeePayHistory and Person.Person
Query:
Result:
Question 2
We need to change the display of product line categories to make them more understandable. The following
values need to be substituted respectively; 'R'-'Road', 'M'-'Mountain', 'T'-'Touring', 'S'-'Other sale items'. If nothing
is mentioned, then substitute with 'Not for sale'. Return ProductNumber, category, and name of the product. Sort
the result set in ascending order on ProductNumber. Table: production.Product
Result:
Question 3
Find the number of employees working in each of the 16 departments. Which Department has occupied the 10th
place when the result is arranged from least strength to most? Name the Department and the number of
employees working. (Tables: [HumanResources].[Department] & [HumanResources].
[EmployeeDepartmentHistory])
Result:
Question 4
Find the Quantity ordered in each Sales Territory. (HINT: check the tables which have Sales.[…] for your reference
tables.
Query: SELECT
ST.Name AS SalesTerritory,
SUM(SOD.OrderQty) AS QuantityOrdered
FROM
[Sales].[SalesOrderHeader] AS SOH,
[Sales].[SalesOrderDetail] AS SOD,
[Sales].[SalesTerritory] AS ST
WHERE
SOH.SalesOrderID = SOD.SalesOrderID
AND SOH.TerritoryID = ST.TerritoryID
GROUP BY ST.Name
Result:
Question 5
From the following table write a query in SQL to retrieve the total sales for each year. Filter the result set for those
orders where order year is on or before 2016. Return the year part of orderdate and total due amount. Sort the
result in ascending order on year part of order date. Use table Sales.SalesOrderHeader
Result: