【Mysql学习日志】基本命令(二)

 

练习题:

【Mysql学习日志】基本命令(二)

 链表案例

1.查询成绩表显示如下:

【Mysql学习日志】基本命令(二)

 

一、

SELECT
    score.sid,
    student.sname,
    student.gender,
    course.cname,
    score.number 
FROM
    score,
    student,
    course 
WHERE
    score.student_id = student.sid 
    AND score.corse_id = course.cid;

 二、

SELECT
    score.sid,
    student.sname,
    student.gender,
    course.cname,
    score.number 
FROM
    score
    LEFT JOIN student ON score.student_id = student.sid
    LEFT JOIN course ON score.corse_id = course.cid;

 

 组合与链表查询:

2.查询每个学生的平均成绩并显示【学号、姓名、平均成绩】:、

【Mysql学习日志】基本命令(二)

一、

SELECT
score.sid AS 学号, student.sname AS 姓名, avg( score.number ) AS 平均成绩 FROM score LEFT JOIN student ON score.sid = student.sid GROUP BY score.sid

二、

SELECT
    学号,
    student.sname AS 姓名,平均成绩 
FROM
    ( SELECT sid AS 学号, avg( number ) AS 平均成绩 FROM score GROUP BY sid ) AS T
    LEFT JOIN student ON T.学号 = student.sid

 

【Mysql学习日志】基本命令(二)

上一篇:P3302 [SDOI2013]森林


下一篇:mysql~数据导入导出