S
S
smoln2018-05-24 11:49:27
MySQL
smoln, 2018-05-24 11:49:27

How to correctly form a mysql query?

Good afternoon, help me formulate the request correctly. If there is an example, I will be glad to see it visually.
the table consists of
brand (there are many different brands)
article (there are many articles, different brands can have the same article)
price
delevery
The output should be as follows:
three positions of the brand-article bundle
sorted
by the minimum price (first position) minimum delivery time (second position) and the ratio of price and delivery time (third position)
Is it possible to do this all in one request or do I need to make several requests with a limit of 1

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Lander, 2018-05-24
@usdglander

Have you tried to write several different queries and combine them into one using UNION ?

I
Igor, 2018-05-24
@Lopar

The minimum and maximum is simple

SELECT brand, article FROM YourTable WHERE price = (SELECT MIN(price) FROM YourTable);
SELECT brand, article FROM YourTable WHERE delevery = (SELECT MIN(delevery) FROM YourTable);

Misunderstandings:
═ The ratio is price/delivery. The ratio can be calculated for any record in the database. Which line are you interested in?
═ What happens if there are multiple identical minimum prices/delivery times. Take at random? Sort somehow else?
═ The wording “three positions each” is unclear. That is, do you need three lines of exhaust for each entry in the database or something?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question