FROM
FROM Customers c JOIN Orders o ON c.ID = o.CustomerID JOIN OrderDetails od ON o.ID = od.OrderID AND od.ProductID = 111
c.ID | c.Name ------------- 1 | Bob 2 | Jane 3 | Bill 4 | Mary o.ID | o.CustomerID | o.Date -------------------------------- 10 | 1 | 6/10/2021 11 | 3 | 8/1/2021 12 | 2 | 8/4/2021 13 | 4 | 10/20/2022 14 | 1 | 11/18/2022 15 | 4 | 2/1/2023 16 | 4 | 4/12/2023 od.ID | od.OrderID | od.ProductID | od.Amount --------------------------------------------- 100 | 10 | 111 | 100 101 | 11 | 111 | 50 102 | 12 | 111 | 25 103 | 13 | 111 | 10 104 | 14 | 111 | 300 105 | 15 | 111 | 120 106 | 16 | 111 | 60
c.ID | c.Name | LatestOrder | LatestOrderAmount | TotalAllAmounts ----------------------------------------------------------------- 1 | Bob | 11/18/2022 | 300 | 400 2 | Jane | 8/4/2021 | 25 | 25 3 | Bill | 8/1/2021 | 50 | 50 4 | Mary | 4/12/2023 | 60 | 190
join
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)