Group-wise Maximum of a Certain Column

后端 未结 5 1859
长情又很酷
长情又很酷 2020-12-19 16:24

I\'ve got the table:

SELECT * FROM shop;

+---------+--------+------
| article | dealer | price
+---------+--------+------
|    0001 | A      |  3.45
|    00         


        
5条回答
  •  醉梦人生
    2020-12-19 17:11

    Here you go:

    SELECT article, dealer, price
    FROM (SELECT article, dealer, price
          FROM shop
          ORDER BY price DESC) AS h
    GROUP BY article
    

    This solution doesn't even require a MAX() function. :)

    Note: This solution doesn't work with ONLY_FULL_GROUP_BY active and only works in MySQL. This solution is to a certain extent unsupported due to lack of documentation confirming this behavior. It works well for me and has always worked well for me however.

    This method still works on the latest MySQL on sqlfiddle.

提交回复
热议问题