Re: [問題] 請問一個SQL
※ 引述《PsMonkey (痞子軍團團長)》之銘言:
: 硬幹法
: select s.*, m.grade as Math, a.grade as Art, e.grade as English
: from student as s,
: (select * from class where course='math') as m,
: (select * from class where course='art') as a,
: (select * from class where course='english') as e
: where s.name *= m.name and s.name *= a.name and s.name *= e.name
: 這個語法應該是 OK 的,不過,看個概念就好... XD
: *= 應該是 left outter join,我忘記標準的 SQL 要怎麼寫了...
: 不過,說真的為什麼只能用 SQL 呢? ==.==?
: 有時候把事情都丟給 SQL,未必是好事情
How about this?
select student.*,
(select grade from class
where course = 'Math' and student.name=class.name) as Math,
(select grade from class
where course = 'Art' and student.name=class.name) as Art,
(select grade from class
where course = 'English' and student.name=class.name) as English
from student;
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.121.188.247
※ 編輯: ojinjin 來自: 59.121.188.247 (12/12 22:32)
討論串 (同標題文章)
Web_Design 近期熱門文章
PTT數位生活區 即時熱門文章