PrepAway - Latest Free Exam Questions & Answers

You need to create a query for a report

You have a database named Sales that contains the tables shown in the exhibit. (Click the Exhibit button).

You need to create a query for a report. The query must meet the following requirements:
• NOT use object delimiters.
• Use the first initial of the table as an alias.
• Return the most recent order date for each customer.
• Retrieve the last name of the person who placed the order.
The solution must support the ANSI SQL-99 standard.
Part of the correct T-SQL statement has been provided in the answer area. Provide the complete code.

PrepAway - Latest Free Exam Questions & Answers

Answer: See the explanation.

Explanation:
SELECT C.LastName,
MAX(O.OrderDate) AS MostRecentOrderDate
FROM Customers AS C INNER JOIN Orders AS O
ON C.CustomerID=O.CustomerID
GROUP BY C.Lastname
ORDER BY MAX (O.OrderDate) DESC

16 Comments on “You need to create a query for a report

    1. Dieyni says:

      He should say to use ‘FROM Customers AS C INNER JOIN Orders AS O
      ON C.CustomerID=O.CustomerID’ instead of ‘FROM Customers as c, Orders AS O
      where C.CustomerID=O.CustomerID’




      0



      0
  1. Mohamed ALi Ben Amor says:

    I think the above query is not the right answer, suppose we have two customers with the same last name, the above query will select the one that have the most recent order.
    I propose the below answer
    Select C.LastName,Max(O.orderDate) as MostRecentOrderDate from Customers C
    inner join Orders O on c.CustomerID=O.CustomerID
    group by O.CustomerID, C.lastName




    0



    0

Leave a Reply