《Mysql学习mysql 将列值转变为列的方法》要点:
本文介绍了Mysql学习mysql 将列值转变为列的方法,希望对您有用。如果有疑问,可以联系我们。
MYSQL入门-- 插入数据
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 '数学',
SUM(CASE object
WHEN 'physical' THEN score END) AS '物理' FROM rate GROUP BY uname;
转载请注明本页网址:
http://www.vephp.com/jiaocheng/2421.html