Extra Fields with SQL MIN() & GROUP BY

前端 未结 4 1236
孤街浪徒
孤街浪徒 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:08

    Another approach can be using Analytical functions. Here is the query using analytical and ROW_NUM functions

    select first_name, salary from (select first_name,salary, Row_NUMBER() over (PARTITION BY DEPARTMENT_ID ORDER BY salary ASC) as row_count from employees) where row_count=1;

提交回复
热议问题