You have a database named Sales that contains the tables as shown in the exhibit.

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

You need to create a query for a report. The query must meet the following requirements:
Return the last name of the customer who placed the order.
Return the most recent order date for each customer.
Group the results by CustomerID.
Order the results by the most recent OrderDate.
Use the database name and table name for any table reference.
Use the first initial of the table as an alias when referencing columns in a table.
The solution must support the ANSI SQL-99 standard and must NOT use object identifiers.
Part of the correct T-SQL statement has been provided in the answer area. Complete the SQL statement.

A. Please review the part for this answer

microsoft-exams

4 thoughts on “You have a database named Sales that contains the tables as shown in the exhibit.

  1. Does anybody actually check the answers before posting them in an attempt to “help” people?

    SELECT o.LastName ?? – LastName is in Customers NOT Orders and you need an INNER JOIN

    SELECT c.LastName
    MAX(o.OrderDate) AS MostRecentOrderDate
    FROM Sales.Customers AS c
    INNER JOIN Sales.Orders AS o
    ON c.CustomerID=o.CustomerID
    GROUP BY c.CustomerID
    ORDER BY MostRecentOrderDate DESC

  2. Select c.lastname, c.customerid, max(o.orderid) as MostRecentOrderDate
    from customer c
    inner join orders o
    on o.customerid=c.customerid
    group by c.customerid

    “Group the results by CustomerID”

  3. Correct Answer:
    SELECT C.LastName, MAX(O.OrderDate) AS MostOrderDate FROM Customers AS C INNER JOIN Orders AS O ON C.CustomerID = O.CustomerID
    GROUP BY C.CustomerID
    ORDER BY MostOrderDate

    1. SELECT C.LastName, MAX(O.OrderDate) AS MostOrderDate
      FROM Customer AS C INNER JOIN Orders AS O ON C.CustomerID=O.CustomerID
      ORDER BY C.CustomerID
      ORDER BY MostOrderDate;

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.