I want to understand it on this "simple" query example. I wanto to view dates and order IDs with the highest order value (profit) in each quarter of 1997. I can write something like this.
SELECT o.OrderDate, o.OrderID, DATEPART(QUARTER, o.OrderDate) FROM Orders o INNER JOIN (SELECT...) WHERE YEAR(o.OrderDate) = '1997' GROUP BY o.OrderDate, o.OrderID;
OrderDetails contains order value (price). Catch is i don't want to view the value, so i need to use SELECT with INNER JOIN or WHILE (probably INNER JOIN in this case). I have tried multiple solutions and it shows more than 800 rows, when it should only return 4 rows. There is also a problem that
GROUP BY won't really work as expected with OrderDate.
I expect results like this:
Order date | OrderID | Quarter 05.02.1997 | 173412 | 1 05.04.1997 | 421552 | 2 12.07.1997 | 735245 | 3 24.12.1997 | 825425 | 4
Query with some small explanation will be highly appreciated.