SQL33 找出每个学校GPA最低的同学

描述

题目:现在运营想要找到每个学校gpa最低的同学来做调研,请你取出每个学校的最低gpa。

 

######################################方法一###########################################
select 
	up.device_id ,up1.university,up1.gpa
from(
	select
		university,
		min(gpa) as gpa
	from user_profile
	group by university
) as up1
inner join user_profile up on up1.university = up.university and up1.gpa = up.gpa
order by university

######################################方法二###########################################
select device_id,university,gpa
from user_profile
where (university,gpa) in (select university,min(gpa) from user_profile group by university)
order by university

 

 


版权声明:本文为weixin_42698464原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。