You have a database that contains the following tables

Posted by: Pdfprep Category: 70-761 Tags: , ,

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 the LastName and SalesYTD for the three salespersons with the highest year-to-date sales values

.- Include the current year-to-date sales for each salesperson.

.-

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: Please see explanation

Explanation:

SELECT TOP (3) LastName, S.SalesYTDFROM Person as P INNER JOIN SalesPerson AS S

ON P.PersonID = S.SalesPersonID WHERE S.TerritoryID IS NOT NULL ORDER BY S.SalesYTD DESC

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.

References: https://msdn.microsoft.com/en-us/library/ms189463.aspx

Leave a Reply

Your email address will not be published.