SIMULATION
You have a database that contains the following tables.
You need to create a query that lists the lowest-performing salespersons based on the current year-to-date
sales period. The query must meet the following requirements:
Return a column named Fullname that includes the salesperson FirstName, a space, and then LastName.
Include the current year-to-date sales for each salesperson.
Display only data for the three salespersons with the lowest year-to-year sales values.
Exclude salespersons that have no value for TerritoryID.
Construct the query using the following guidelines:
Use the first letter of a table name as the table alias.
Use two-part column names.
Do not surround object names with square brackets.
Do not use implicit joins.Use only single quotes for literal text.
Use aliases only if required.
Part of the correct Transact-SQL has been provided in the answer area below. Enter the code in the answer
area that resolves the problem and meets the stated goals or requirements. You can add code within the code
that has been provided as well as below it.
Use the Check Syntax button to verify your work. Any syntax or spelling errors will be reported by line and
character position.
Answer: See the explanation
Explanation:
SELECT TOP(3) FirstName + ‘ ‘ + LastName AS Fullname, S.SalesYTD
FROM Person as P INNER JOIN SalesPerson AS S
ON P.PersonID = S.SalesPersonID
WHERE S.TerritoryID IS NOT NULL
ORDER BY S.SalesYTD
Explanation;
On ordering: ASC | DESC
Specifies that the values in the specified column should be sorted in ascending or descending order. ASC sorts
from the lowest value to highest value. DESC sorts from highest value to lowest value. ASC is the default sort
order. Null values are treated as the lowest possible values.
https://msdn.microsoft.com/en-us/library/ms189463.aspx
Use aliases only if required so the answer is wrong
it also says “Use two-part column names”.
Select Top(3) P.FirstName + ” + P.LastName AS Fullname, S.SalesYTD
FROM Person AS P
INNER JOIN SalesPerson AS S ON P.PersonID = S.SalesPersonID
WHERE S.TerritoryID IS NOT NULL
Order by S.SalesYTD