Note: This question is part of a series of questions that present the same scenario. Each question in the series contains a unique solution that might meet the stated goals. Some question sets might have more than one correct solution, while others might not have a correct solution.
After you answer a question in this section, you will NOT be able to return to it. As a result, these questions will not appear in the review screen.
You have a database that includes the tables shown in the exhibit (Click the Exhibit button.)
You need to create a Transact-SQL query that returns the following information:
.- the customer number
.- the customer contact name
.- the date the order was placed, with a name of DateofOrder
.- a column named Salesperson, formatted with the employee first name, a space, and the employee last name
.- orders for customers where the employee identifier equals 4
The output must be sorted by order date, with the newest orders first.
The solution must return only the most recent order for each customer.
Solution: You run the following Transact-SQL statement: Does the solution meet the goal?
A . Yes
B . No
Answer: B
Explanation:
We cannot use the column alias Salesperson in the GROUP BY clause, since in Oracle and SQL Server, you cannot use a term in the GROUP BY clause that you define in the SELECT clause because the GROUP BY is executed before the SELECT clause.
References: https://stackoverflow.com/questions/3841295/sql-using-alias-in-group-by/3841804
Leave a Reply