Extra Fields with SQL MIN() & GROUP BY

前端 未结 4 1230
孤街浪徒
孤街浪徒 2020-12-14 02:00

When using the SQL MIN() function, along with GROUP BY, will any additional columns (not the MIN column, or one of the GROUP BY columns) match the data in the matching MIN r

4条回答
  •  感动是毒
    2020-12-14 02:11

    The fastest solution:

    SET @dep := '';
    SELECT * FROM (
      SELECT * FROM `employee` ORDER BY `department`, `salary`
    ) AS t WHERE IF ( @dep = t.`department`, FALSE, ( @dep := t.`department` ) OR TRUE );
    

提交回复
热议问题