Re: [SQL ] SQL練習題
select Selected_Student.student_ID,Selected_Student.name,sum(SCORE.score) as '
總分', avg(SCORE.score) as '平均' from ((select * from STUDENT where grade=1
limit 100) union
(select * from STUDENT where grade=2 limit 100) union
(select * from STUDENT where grade=3 limit 100) union
(select * from STUDENT where grade=4 limit 100) union
(select * from STUDENT where grade=5 limit 100) union
(select * from STUDENT where grade=6 limit 100)) as Selected_Student inner
join SCORE on Selected_Student.student_ID = SCORE.student_ID group by
Selected_Student.student_ID
※ 引述《john9872 (菸酒生)》之銘言:
: 假設我有兩個資料表,分別為"學生"及"成績",
: 資料欄位分別為: ( student_ID, 姓名, 年級 ) 及
: ( 成績流水號, student_ID, 科目, 分數 ),
: 資料內容如下圖例:
: "學生"資料表 "成績"資料表
: ------------- -------------
: student_ID 姓名 年級 成績流水號 student_ID 科目 分數
: ============================ ====================================
: 1 小黃 1 1 1 國文 60
: 2 小白 2 2 1 數學 70
: 3 小虎 3 3 1 英文 50
: 4 小便 4 5 2 國文 12
: . . . . . .
: . . . . . .
: . . . . . .
: 假設學生資料表共有900筆(共有1~6年級),成績資料表1800筆(國英數3科),
: 請問要怎麼從1~6年級各挑出100名學生(共600名),並計算出他們的成績及總分呢?
: 以下是我寫的SQL:
: SELECT student_ID, SUM(分數), AVG(分數)
: FROM 學生
: GROUP BY student_ID
: ....
: 由於我是SQL初心者,所以太複雜的SQL語法還不太能理解,
: 目前是卡在要取各年級100名學生的部分,
: 不知道該如何運用WHERE或其他指令寫出來(題目也有提示用JOIN)
: 麻煩大家替我解惑,謝謝各位:)
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 125.231.102.104
推
12/31 21:15, , 1F
12/31 21:15, 1F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 3 篇):