SQL33 找出每个学校GPA最低的同学
select a.device_id, a.university uni, a.gpa from user_profile a inner join (select min(gpa) min_gpa, university from user_profile group by university) b on a.university = b.university and a.gpa = b.min_gpa order by uni asc;
刚开始使用子查询:
select ... from ... gpa = (select min(gpa) from ... group by ...) and university = (selectuniversity from ... group by ....);
报错:子查询返回的row > 1。
之后改为in,返回的结果出现两个清华大学,依旧有错。
最终改为了本文最开始的子表join形式。