Answer the question
In order to leave comments, you need to log in
How to make the following request?
There are two tables:
1)
contains, for example, a certain price
and 2)
contains the id of the price ranges from the first table. That is, id_1 is the id of the beginning of the range, and id_2 is the rightmost id of the range.
Tell me how to make a query in which we will get a selection with the maximum prices of each of the ranges?
Ie, for our case, the sample should be as follows:
Example of counting for a range with id_1=4 and id_2=7:
I.e. you need to find the maximum price between these id.
id=4 price 20
id=5 price 5
id=6 price 3
id=7 price 100
Maximum price from this range = 100
Answer the question
In order to leave comments, you need to log in
GREATEST( prices1.value, prices2.value )
SELECT ID_1, ID_2,
( SELECT MAX( Value ) FROM Prices WHERE ID BETWEEN ID_1 AND ID_2 ) AS PriceMax
FROM Range
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question