Pokaż pierwsze i ostatnie zamówienie dla klientów z Niemiec.
Baza: Northwind, Tabele: dbo.Orders, dbo.Customers, Kolumny: CustomerID, OrderID, Country, Wynik: 11 rows
[spoiler title=’Rozwiązanie’ collapse_link=’true’]SELECT CustomerID, MIN(OrderID) as FirstOrder, MAX(OrderID) as LastOrder
FROM dbo.Orders
GROUP BY CustomerID
HAVING CustomerID in (SELECT CustomerID FROM dbo.Customers WHERE Country = 'Germany’)
ORDER BY CustomerID;
[/spoiler]