[英]SQL select statement where one course more than other
您可以使用group by
和having
来执行此操作:
select name
from t
where course in ('Eng', 'Geo')
group by name
having max(case when course = 'Eng' then score end) > max(case when course = 'Geo' then score end);
如果每个名称/课程只有一个分数,您还可以使用如下的join
:
select teng.name
from t teng join
t tgeo
on teng.name = tgeo.name and
teng.course = 'Eng' and
tgeo.course = 'Geo' and
teng.score > tgeo.score;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.