exam questions

Exam 70-761 All Questions

View all questions & answers for the 70-761 exam

Exam 70-761 topic 1 question 26 discussion

Actual exam question from Microsoft's 70-761
Question #: 26
Topic #: 1
[All 70-761 Questions]

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.

Show Suggested Answer Hide Answer
Suggested Answer: Please see 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.
References:
https://msdn.microsoft.com/en-us/library/ms189463.aspx

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
okh
Highly Voted 5 years, 7 months ago
Should be ON S.PersonID = P.PersonID
upvoted 15 times
...
moehijawe
Highly Voted 5 years, 4 months ago
select top(3) concat(p.FirstName, ' ', p.lastname) as FullName, s.SalesYTD as SalesYTD from SalesPerson as s join Person as p on(s.PersonId = p.PersonId) where s.TerritoryID is not null order by s.SalesYTD
upvoted 11 times
Ricky7876
4 years, 12 months ago
The default order by is already ASC, so I don't think we need to include that
upvoted 3 times
...
...
Vermonster
Most Recent 4 years, 4 months ago
Important to use CONCAT or get NULL. This fits.... SELECT TOP(3) CONCAT(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
upvoted 1 times
...
Korongo
4 years, 9 months ago
Ok, I understand now, the insturctions force to use SalespersonID and PersonID, no S.PersonID = P.PersonID
upvoted 1 times
Andy7622
4 years, 5 months ago
You cannot do that these are to differnt columns
upvoted 1 times
...
...
julie2020
4 years, 9 months ago
SELECT Top(3) CONCAT(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 NOTE: Use aliases only if required. SalespersonID and PersonID are only connected through pk & fk.
upvoted 1 times
...
julie2020
4 years, 9 months ago
SELECT Top(3) CONCAT(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 NOTE: Use aliases only if required. SalespersonID and PersonID are only connected through pk & fk.
upvoted 1 times
Andy7622
4 years, 5 months ago
Sorry, You have a mistake in 'ON' clause. Must be ON p.PersonID =s.PersonID
upvoted 3 times
...
...
vermeilyn
4 years, 11 months ago
You guys are joining on the wrong key. Notice that there is no PersonID in Salesperson table, only SalesPersonID.
upvoted 1 times
Joeyboats
4 years, 10 months ago
There is a personID in both tables
upvoted 1 times
...
AI_Cheong
4 years, 10 months ago
forget about he key,,, the question is asking to fill-in-the-blank on the select and where cause.
upvoted 1 times
...
...
Robintang0924
5 years, 3 months ago
Besides correct join column, we should also consider possible null values since there is no clear declaration of those columns: 1. NULLability of firstname and lastname, any of null values in these 2 columns could result in a null full name which is NOT what we wanted, Moehijawe already provided a good solution of using concat which could safely take care of null and yield meaning result of concated string. 2. SalesYTD, if it contains null value, then we might see first 3 rows as null value since null is considered the lowest value. Above being said, below SQL should be a more complete solution to question(I wish I could come up with something in an elegant way like 'order by s.SalesYTD nulls last' but unfortunately SQL server doesn't support this ANSI SQL feature ): select top(3) concat(p.FirstName, ' ', p.lastname) as FullName, s.SalesYTD as SalesYTD from SalesPerson as s join Person as p on(s.PersonId = p.PersonId) where s.TerritoryID is not null ORDER BY CASE WHEN s.SalesYTD IS NULL THEN 1 ELSE 0 END, s.SalesYTD;
upvoted 3 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago