mysql橫表縱錶轉換

一.橫錶轉縱表數學

select id,姓名,'語文' as SUBJECT,語文 as 'score' from hb 
UNION
select id,姓名,'數學' as SUBJECT,數學 as 'score' from hb 
UNION
select id,姓名,'英語' as SUBJECT,英語 as 'score' from hb select

二.縱錶轉橫表im

select name as '姓名',MAX(CASE `subject` WHEN '語文' then score else 0 end) 語文,
MAX(CASE `subject` WHEN '數學' then score else 0 end) 數學,
MAX(CASE `subject` WHEN '英語' then score else 0 end) 英語 from sb group by nameimg

相關文章
相關標籤/搜索