MySQL - Fetching lowest value

后端 未结 7 1261
醉酒成梦
醉酒成梦 2020-12-06 03:14

My database structure contains columns: id, name, value, dealer. I want to retrieve row with lowest value for each dealer

7条回答
  •  自闭症患者
    2020-12-06 03:26

    First you need to resolve the lowest value for each dealer, and then retrieve rows having that value for a particular dealer. I would do this that way:

    SELECT a.*
    FROM   your_table AS a
           JOIN (SELECT dealer,
                        Min(value) AS m
                 FROM   your_table
                 GROUP  BY dealer) AS b
             ON ( a.dealer= b.dealer
                  AND a.value = b.m ) 
    

提交回复
热议问题