select
case when enter_date >= '2010-01-01' then '青年教师'
when enter_date < '2000-01-01' then '资深教师'
else '中年教师'
end as teacher_type,
count(*) as teacher_count
from teachers
GROUP BY teacher_type;
SELECT
student_id,
MAX(score) AS max_score,
MIN(score) AS min_score,
AVG(score) AS avg_score
FROM scores
WHERE student_id in (460093,735011) AND subject = '数学'
group by student_id
select
st.class_code,
count(distinct st.student_id) as num_students_90_plus,
round(avg(sc.score) , 2)as avg_score_90_plus,
te.name as physics_teacher
from
students as st
join
scores sc on st.student_id = sc.student_id
join
teachers te on te.class_code like concat('%',st.class_code,'%')
where
te.subject = '物理'
and sc.score >= 90
and sc.subject = '物理'
group by
st.class_code, te.name
order by
avg_score_90_plus desc
WITH ranked_scores AS (
SELECT
s.student_id,
s.name,
sc.score,
RANK() OVER (ORDER BY sc.score DESC) AS ranking
FROM
students s
JOIN
scores sc ON s.student_id = sc.student_id
WHERE
s.grade_code = 'S1'
AND sc.subject = '物理'
)
SELECT
student_id,
name,
score,
ranking
FROM
ranked_scores
WHERE
ranking <= 10
ORDER BY
ranking;