作者ojinjin (小歐)
看板Web_Design
標題Re: [問題] 請問一個SQL
時間Mon Dec 12 18:55:28 2005
※ 引述《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)