1. 程式人生 > 其它 >資料結構 線索二叉樹

資料結構 線索二叉樹

技術標籤:MySql

目錄

提前準備的表

1. 學生表

2. 教師表

3. 課程表

4. 成績表

練習開始

1. 查詢1號課程比2號課程成績高的所有學生的學號;

2.查詢平均成績大於60分的同學的學號和平均成績並從高到低降序排序;

3.查詢所有同學的學號、姓名、選課數、總成績,並按總成績降序排序;

4.查詢姓"黃"的老師的個數;

5.查詢選修"林老師"課的同學的學號、姓名;


提前準備的表

1. 學生表

2. 教師表

3. 課程表

4. 成績表

練習開始

1. 查詢1號課程比2號課程成績高的所有學生的學號;

select a.S_id
from 
(select score , S_id from Score where C_id = 1)  a,
(select score , S_id from Score where C_id = 2)  b
where
a.score > b.score and a.S_id = b.S_id;

2.查詢平均成績大於60分的同學的學號和平均成績並從高到低降序排序;

 select S_id,AVG(score) as AvgScore 
 from Score
 group by S_id
 having AvgScore>60
 order by AvgScore desc;

3.查詢所有同學的學號、姓名、選課數、總成績,並按總成績降序排序;

 select s.S_id , s.Sname , count(c.C_id) as courseCount , sum(c.score) as sumScore
 from
 Student as s left join Score as c
 on s.S_id = c.S_id
 group by s.Sname
 order by sumScore desc;

4.查詢姓"黃"的老師的個數;

 select count(T_id) as Count
 from Teacher
 where Tname like '黃%'

5.查詢選修"林老師"課的同學的學號、姓名;

 select s.S_id as id,s.Sname as name
 from
 Student as s,
 Course as c,
 Score as sc,
 (select T_id from Teacher where Tname = '林老師') as t
 where
 c.T_id = t.T_id and s.S_id = sc.S_id and sc.C_id = c.C_id;

待更新.....

原帖傳送門:點選前往