A
A
Alexey Denisov2019-11-26 03:47:57
SQL
Alexey Denisov, 2019-11-26 03:47:57

Display a List of Products with the Largest Weight?

Hello, please help me to write a database query.
There is a table with the name of the goods, each product has a PRICE and WEIGHT,
in the table there are goods with the same Name, but with different WEIGHT, it is
required to display a list of the heaviest goods.
Such a Request - will display One item with max. weighing

"SELECT * FROM product WHERE massa=(SELECT MAX(massa) FROM product"

Here is the table:
names     |massa  | price
 ____________ |_____  |______
песок (мешки) | 30.00 | 150
песок (мешки) | 35.50 | 170
песок (мешки) | 32.00 | 161
глина (мешок) | 17.00 | 55
глина (мешок) | 17.15 | 57
цемент        | 25.00 | 100
цемент        | 30.00 | 150

Should output like this:
песок (мешки) 35.50 | 170
глина (мешок) 17.15 | 57
цемент        30.00 | 150

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2019-11-26
@Denisov80

Try like this:

SELECT *, `names` as `nm` 
FROM `product` 
HAVING `massa` = (
    SELECT max(`massa`) 
    FROM `product` 
    WHERE `names` = `nm`
) 
ORDER BY `names` 
ASC
WB_7jOTLfjU.jpg

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question