My database structure contains columns: id, name, value, dealer . I want to get the row with the lowest value for each dealer . I tried to get confused with MIN() and GROUP BY , still without a solution.
id, name, value, dealer
value
dealer
MIN()
GROUP BY
Solution1:
SELECT t1.* FROM your_table t1 JOIN ( SELECT MIN(value) AS min_value, dealer FROM your_table GROUP BY dealer ) AS t2 ON t1.dealer = t2.dealer AND t1.value = t2.min_value
Solution2:
SELECT t1.* FROM your_table t1 LEFT JOIN your_table t2 ON t1.dealer = t2.dealer AND t1.value > t2.value WHERE t2.value IS NULL
This problem is very well known, so there is a special page in the Mysql manual.
Check this out: Rows holding the group maximum / minimum of a specific column
select id,name,MIN(value) as pkvalue,dealer from TABLENAME group by id,name,dealer;
here you group all the lines by id, name, dealer, and then you get the min value as pkvalue.
SELECT MIN(value),dealer FROM table_name GROUP BY dealer;
Try the following:
SELECT dealer, MIN(value) as "Lowest value" FROM value GROUP BY dealer;
First you need to decide the lowest value for each dealer, and then get the rows that have this value for a particular dealer. I would do this:
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 = bm )
select id, name, value, dealer from yourtable where dealer in(select min(dealer) from yourtable group by name, value)
Source: https://habr.com/ru/post/1435876/More articles:passing char * [] from C ++ dll Struct to C # - c ++Unable to start new xcode 4.5 project even with a single label on ios 5.1.1 device - iosC ++ binary identification (manifest) - c ++IE 8: remove node save children - javascriptjqueryUI sortable: how to force update the position of a replacement item when dragging and dropping - jqueryIs there a limit on fql request length? - facebook-graph-apiStretch on overflow error text box interval? - jasper-reportsARC converts the application with the last call .cxx_destruct - objective-cComponent container access page in .net based CT - tridionGet the path to the application to create a new file - javaAll Articles