分析:平均 avg:GROUP BY分组
从高到低:ORDER BY
所有学生的所有课程的成绩:行转列
所有学生----外联(所有):RIGHT JOIN右联
语句:
SELECT
s.sid,
s.sname ,
sum((case when sc.cid='01' then sc.score end))语文,
sum((case when sc.cid='02' then sc.score end))数学,
sum((case when sc.cid='03' then sc.score end))英语,
ROUND(avg(sc.score),2)
FROM
t_mysql_score sc
RIGHT JOIN t_mysql_student s ON sc.sid = s.sid
GROUP BY
s.sid,
s.sname
SELECT
s.sid,
s.*,
sc.score
FROM
t_mysql_student s,
t_mysql_score sc
WHERE
s.sid = sc.sid
AND sc.cid = '01'
AND sc.score < 60
ORDER BY
sc.score desc
SELECT
s.sid,
s.sname,
avg(sc.score) n
from
t_mysql_student s,
t_mysql_score sc
where
s.sid=sc.sid
and
sc.score<60
GROUP BY s.sid,
s.sname
SELECT
s.sid,
s.sname
FROM
t_mysql_score sc,
t_mysql_student s
WHERE
s.sid = sc.sid
AND
sc.cid NOT IN
(SELECT cid FROM t_mysql_course c, t_mysql_teacher t
WHERE c.tid = t.tid AND t.tname = '张三')
GROUP BY
s.sid,
s.sname
SELECT
s.sid,
s.sname,
count( sc.score ) n
FROM
t_mysql_student s
LEFT JOIN t_mysql_score sc ON s.sid = sc.sid
GROUP BY
s.sid,
s.sname
HAVING
n < (SELECT count(*) FROM t_mysql_course)
SELECT
s.*,
c.cname,
t.tname,
sc.score
FROM
t_mysql_course c,
t_mysql_student s,
t_mysql_teacher t,
t_mysql_score sc
WHERE
t.tid = c.tid
AND c.cid = sc.cid
AND sc.sid = s.sid
AND t.tname = '张三'
SELECT
c.cid,
c.cname,
count(sc.sid) 人数,
max(sc.score) 最高分,
min(sc.score) 最低分,
ROUND(avg(sc.score),2) 平均分 ,
CONCAT(ROUND(sum(if(sc.score>=90,1,0))/(SELECT count(1)
from
t_mysql_student)*100,2),'%') 优秀率,
CONCAT(ROUND(sum(if(sc.score>=80 and sc.score<90,1,0))/(SELECT count(1)
from t_mysql_student)*100,2),'%') 优良率,
CONCAT(ROUND(sum(if(sc.score>=70 and sc.score<80,1,0))/(SELECT count(1)
from t_mysql_student)*100,2),'%') 中等率,
CONCAT(ROUND(sum(if(sc.score>=60,1,0))/(SELECT count(1)
from t_mysql_student)*100,2),'%') 及格率
FROM
t_mysql_score sc
LEFT JOIN t_mysql_course c ON sc.cid = c.cid
GROUP BY
c.cid,
c.cname