SELECT Name ,
SUM(CASE WHEN Course = N'語(yǔ)文' THEN Grade
ELSE 0
END) AS Chinese ,
SUM(CASE WHEN Course = N'數(shù)學(xué)' THEN Grade
ELSE 0
END) AS Mathematics ,
SUM(CASE WHEN Course = N'英語(yǔ)' THEN Grade
ELSE 0
END) AS English
FROM dbo.Table_A
GROUP BY Name
SELECT Name ,
'Chinese' AS Course ,
Chinese AS Score
FROM dbo.Table_B
UNION ALL
SELECT Name ,
'Mathematics' AS Course ,
Mathematics AS Score
FROM dbo.Table_B
UNION ALL
SELECT Name ,
'English' AS Course ,
English AS Score
FROM dbo.Table_B
ORDER BY Name ,
Course DESC
以上所述是小編給大家介紹的SQL Server縱表與橫表相互轉(zhuǎn)換的實(shí)現(xiàn)方法,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!