For example, there is a table with customers and there is a table with orders. In the query, I join these tables by customer id, but I end up with only a list of customers with summary data on orders. So, I need to get an order with a minimum amount in the query results. I can derive the minimum amount itself using the min function (column_c_summa), but how can I display, for example, another field from the table with orders corresponding to the minimum amount? Of course, I can do something like
SELECT п.покупатель , (SELECT Другое_поле FROM заказы зак WHERE зак.столбец_с_суммой = min(п.покупатель) AND зак.покупательИД = п.покупательИД) FROM покупатели п JOIN заказы з ON з.покупательИД = п.покупательИД GROUP BY п.покупатель but it turns out a request for data that is already selected in the main request. My instinct tells me that window expressions can be used here, but I have never worked with them, I could not find any ready examples and cannot figure it out yet.