2014-03-07 57 views

回答

3

That'a常見的問題,搜索「PIVOT查詢」 :-)

假設一個名稱可以有你需要使用MAX/GROUP BY多個主題,否則只需刪除聚集。

select 
    Name, 
    max(case when Subjects = 'math' then 'Y' else 'N' end) as Math, 
    max(case when Subjects = 'science' then 'Y' else 'N' end) as Science, 
    max(case when Subjects = 'english' then 'Y' else 'N' end) as English 
from tab 
group by Name 
相關問題