sql - SQL 选择语句,其中一门课程多于另一门课程
解决方案
您可以使用group by
and执行此操作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
s,例如:
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;
推荐阅读
- casting - 由于空值,无法将红移列转换为整数
- javascript - 使用所选选项更改跨度文本
- mysql - 在MYSQL上选择带有条件的上一行或下一行
- next.js - 错误:502:{“errorMessage”:“任务在 10.01 秒后超时”} nextJS netlify
- java - Android 上的全局对象数据库
- angular - DevExtream MultiSelect 下拉框 自定义外观
- reactjs - 反应 - 从 s3 获取图像时,请求的资源上不存在“Access-Control-Allow-Origin”标头
- ruby-on-rails - Rake 任务 Rails 中止:连接被拒绝 10061
- r - 使用 recode() 和通过 paste() 生成的变量名
- bootstrap-4 - 使用按钮的 onClick 事件显示引导选项卡