This section provides solutions to the exercises in the preceding section.
You can write a self-contained subquery that returns the maximum order date from the Orders table. You can refer to the subquery in the WHERE clause of the outer query to return all orders that were placed on the last day of activity. Here’s the solution query:
USE TSQLFundamentals2008; SELECT orderid, orderdate, custid, empid FROM Sales.Orders WHERE orderdate = (SELECT MAX(O.orderdate) FROM Sales.Orders AS O);
This problem is best solved in multiple steps. First, you can write a query that returns the customer or customers who placed the highest number of orders. You can achieve this by grouping the orders by customer, ordering the customers by COUNT(*) descending, ...