此题主要考察开窗函数。

  • 首先,根据gpa进行开窗排序
select 
    device_id,
    university,
    gpa,
    row_number() over(partition by university order by gpa) as ranking
from user_profile
  • 然后根据开窗结果,再选出最小序号条件的gpa,结果:
select 
    device_id,
    university,
    gpa 
from (select 
          device_id,
          university,
          gpa,
          row_number() over(partition by university order by gpa) as ranking
      from user_profile) as t
where ranking=1