《Mysql學(xué)習(xí)mysql 將列值轉(zhuǎn)變?yōu)榱械姆椒ā芬c:
本文介紹了Mysql學(xué)習(xí)mysql 將列值轉(zhuǎn)變?yōu)榱械姆椒ǎM麑δ杏谩H绻幸蓡枺梢月?lián)系我們。
MYSQL入門-- 插入數(shù)據(jù)
INSERT INTO test.rate (uname, object, score)
?VALUES('aaa', 'chinese', '67'),
?('aaa', 'math', '89'),
?('aaa', 'physical', '89'),
?('bbb', 'chinese', '67'),
?('bbb', 'math', '75'),
?('bbb', 'physical', '89');
MYSQL入門
-- 查詢
SELECT DISTINCT uname AS '姓名',
SUM(CASE object
WHEN 'chinese' THEN score END)? AS '語文',
SUM(CASE object
WHEN 'math' THEN score END)? AS '數(shù)學(xué)',
SUM(CASE object
WHEN 'physical' THEN score END)? AS '物理' FROM rate GROUP BY uname;
轉(zhuǎn)載請注明本頁網(wǎng)址:
http://www.snjht.com/jiaocheng/2421.html