首页 >

查询成绩

select  
    count(*)
from (
    select  
        sId,
        avg(score) as score 
    from SC
    join Student using(sId)
    join Course using(cId)
    where SC.sId = Student.sId 
        and cname in ('英语','数学','语文')
    group by sId 
) as sub
where sub.score > 60

逆天大小写
发表于 2025-03-16 16:01:32 回复(3)
本题需要注意的点:
1、要先过滤出语文、数学、英语这三门课程,在实际中表中可能不止这三门课程,我们也不知道课程对应的具体编号,只能通过需求要求的过滤条件过滤
2、要确保计算平均分时,学生的确参与了语数英3门考试,排除缺考的可能
select count(*)
from(
    select sId, avg(score) avg_s
    from SC 
    where cId in (
        select cId
        from Course
        where cname in ('语文','数学','英语')
)
group by sId
having count(DISTINCT cId) = 3
)t1
where avg_s>60



发表于 2025-03-12 11:29:29 回复(1)
这题出的有问题吧,SC表中sId = 5 的去哪了??直接打印select * from SC都没5的结果
发表于 2025-03-18 11:15:50 回复(1)
注意:sid 的 i 大写
select count(*)
    from (
    select sId,avg(score) as avs
    from SC 
    group by sId) t1
where avs>60

发表于 2024-12-26 17:46:01 回复(0)
select count(*)
from(
select
a.sid,
avg(b.score) as avg_score
from SC b
join Student a on a.sid=b.sid
join Course c on b.cId = c.cid
where c.cname in ('语文','数学','英语')
group by a.sid
having avg(score) > 60
) w
询出语文,数学,英语3科的平均成绩大于60分的学生人数。
1.三科平均数,限制这三科,where c.cname in ('语文','数学','英语')这句代码的作用是筛选出指定课程的成绩记录。
2.平均成绩大于60的学生,查询学生的sid,并且计算平均数,这个平均数要按不同学生分组group by a.sid,分完组后查询平均数大于60having avg(score) > 60
3.查询人数,把之前的查询看作表w,计算表的计数即可


发表于 2025-05-22 11:47:10 回复(0)
select  
    count(*)
from (
    select  
        sId,
        avg(score) as score 
    from SC
    join Student using(sId)
    join Course using(cId)
    where SC.sId = Student.sId 
        and cname in ('英语','数学','语文')
    group by sId 
) as sub
where sub.score > 60

发表于 2025-07-02 21:46:37 回复(0)
这个大小写把我害惨了
发表于 2025-06-28 11:28:44 回复(0)
select
count(1) `count(*)`
from
(
select
SC.sId
,avg(score) 三科平均成绩
from Student
join SC
on Student.sId = SC.sId
group by 1
) a
where 三科平均成绩 > 60
发表于 2025-06-03 21:06:16 回复(0)
with sc_course as (
select 
  s.sId,
  s.cId,
  c.cname,
  s.score,
  count(s.cId)over(partition by s.sId) as rn
from SC s
inner join Course c on s.cId = c.cId
where s.score is not null
),
sc_course1 as (
select
  sId
 from sc_course 
where rn = 3
group by sId
having avg(score) > 60
)
select count(*) 
from sc_course1
-- 避免出现只有两科成绩的情况
发表于 2025-06-02 20:17:56 回复(0)
select
    count(*)
from
    (select
        sc.sid
        , avg(sc.score) as avg_score
    from
        SC as sc
        left join Student as s on sc.sid = s.sid
    group by
        sc.sid
    ) as t1
where
    avg_score > 60

发表于 2025-05-22 15:07:36 回复(0)
select count(*)
from (
select sname
    ,avg(score) as score 
from Student a
left join SC b  on a.sId = b.sId
left join Course c  on b.cId = c.cId
where cname in ('语文','数学','英语')
group by sname
having score > 60 
)t

发表于 2025-05-07 15:42:11 回复(0)
SELECT count(*)
FROM(
   SELECT SC.sId AS sId,
          avg(SC.score) AS avg_score
   FROM SC
   INNER JOIN Course C ON C.cId = SC.cId
   WHERE C.cname IN ('语文' ,'数学', '英语')
   GROUP BY SC.sId
   HAVING avg(IF(score IS NULL,0,score)) > 60 )
这样为什么错呀?
发表于 2025-05-07 10:39:06 回复(0)
WITH tmp 
AS(SELECT 
AVG(SC.score)
FROM 
Student st
JOIN 
SC
ON
st.sId =  SC.sId
GROUP BY SC.sId 
HAVING AVG(SC.score)> 60
)
SELECT 
count(*)
FROM 
tmp


发表于 2025-05-02 16:59:27 回复(0)
俺真服了,搞半天是大小写
select count(*) from (select Student.sId from Student join SC on Student.sId=SC.sId
join Course on Course.cId=SC.cId
where Course.cname="语文" or Course.cname="数学" or Course.cname="英语"
group by Student.sId
having avg(SC.score)>60) s

发表于 2025-04-27 11:45:15 回复(0)
with a as(
select sname,sum(score)/3 as avg
from SC s1
join
Student s2
join
Course c1
on s1.sId=s2.sId and s1.cId= c1.cId
where cname in ('语文','数学','英语')
group by sname
having avg>60)
select count(*) from a
发表于 2025-04-25 10:21:48 回复(0)
select count(*)
from(
select a.sId
from  Student a
left join  SC b
on a.sId=b.sId
left join Course c
on b.cId =c.cId
where c.cname in('语文','数学','英语')
group by a.sId
having(avg(score)>60)
)t
发表于 2025-04-11 14:58:10 回复(0)
with t as (
select sId,
avg(score)
from SC
group by sId
having avg(score)>60
)
select count(*)
from t
应该是最简单的做法了吧
发表于 2025-04-11 14:54:53 回复(0)
select count(*)
from(
    select st.sid
from SC sc
left join Course ce on sc.cid = ce.cid
left join Student st on sc.sid = st.sid  
group by st.sid
having avg(sc.score) > 60
) ss

发表于 2025-04-02 23:23:32 回复(0)
select count(sid)
from(
select
a.sid,
avg(b.score) as avg_score
from SC b
join Student a on a.sid=b.sid
join Course c on b.cId = c.cid
where c.cname in ('语文','数学' , '英语')
group by a.sid
having avg(score) > 60
) w;
发表于 2025-03-25 12:09:23 回复(0)
with t as (
select
    sid,
    count(cid) as cnt
from SC
where sid not in (select sid from SC where score <= 60)
group by sid
having cnt >= 3 )
select  
    count(*)
from t


发表于 2025-03-24 23:34:41 回复(0)