with t_avg_score as (
select avg(score) avg_score
from exam_record record
join examination_info info
using (exam_id)
where info.tag='SQL'
)
select min(score) min_score_over_avg
from exam_record
join examination_info info
using (exam_id)
where info.tag='SQL' and score >= (select avg_score from t_avg_score)
;
也可以通过limit取结果集头一条:
with t_avg_score as (
select
avg(score) avg_score
from exam_record record
join examination_info info
using (exam_id)
where info.tag='SQL'
)
select score min_score_over_avg
from exam_record
join examination_info info
using (exam_id)
where info.tag='SQL' and score >= (select avg_score from t_avg_score)
order by score asc
limit 1
;