1、如表
要把表中的数据查询为下图所示:
SQL语句为:
SELECT z.`NAME` AS 姓名,
sum(CASE z.KEMU WHEN '语文' THEN z.SCORE ELSE 0 END ) AS 语文,
sum(CASE z.KEMU WHEN '数学' THEN z.SCORE ELSE 0 END) AS 数学,
sum(CASE z.KEMU WHEN '英语' THEN z.SCORE ELSE 0 END ) AS 英语, SUM(z.SCORE) AS 总分 from test_zx z
GROUP BY z.`NAME`