April 2006
Intermediate to advanced
640 pages
16h 46m
English
Now that the fundamentals of TOP and APPLY have been covered, I’ll present common problems and solutions that use TOP and APPLY.
In Chapter 4 and Chapter 6, I discussed a problem involving tiebreakers where you were asked to return the most recent order for each employee. This problem is actually a special case of a more generic problem where you are after the top n rows for each group—for example, returning the three most recent orders for each employee. Again, orders with higher OrderDate values have precedence, but you need to introduce a tiebreaker to determine precedence in case of ties. Here I’ll use the maximum OrderID as the tiebreaker. I’ll present solutions to this class ...
Read now
Unlock full access