mysql group by to return a the min value and get the corresponding row data

后端 未结 1 1329
春和景丽
春和景丽 2021-01-19 07:16

I have a table of data like so :

- PK_table - merchantName - price - Product
- 1        - argos        - 7     - 4
- 2        - comet        - 3     - 4
- 1          


        
相关标签:
1条回答
  • 2021-01-19 07:44
    SELECT Merchant.Product, Merchant.Name, Merchant.Price
    FROM a_table AS Merchant
    JOIN
    (
    SELECT Product, MIN(Price) AS MinPrice
    FROM a_table
    GROUP BY Product
    ) AS Price
    ON Merchant.Product = Price.Product
    AND Merchant.Price = Price.MinPrice
    

    Will return two rows if two merchants have the same low, low price.

    0 讨论(0)
提交回复
热议问题