1.行转列存储过程实现方式
准备数据:
CREATE TABLE studentscores
(
username
varchar(20) COLLATE utf8_bin DEFAULT NULL,
subjectname
varchar(30) COLLATE utf8_bin DEFAULT NULL,
score
double DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin ROW_FORMAT=DYNAMIC;
INSERT INTO crm
.studentscores
(username
, subjectname
, score
) VALUES (‘张三’, ‘语文’, 80);
INSERT INTO crm
.studentscores
(username
, subjectname
, score
) VALUES (‘张三’, ‘数学’, 90);
INSERT INTO crm
.studentscores
(username
, subjectname
, score
) VALUES (‘张三’, ‘英语’, 70);
INSERT INTO crm
.studentscores
(username
, subjectname
, score
) VALUES (‘张三’, ‘生物’, 85);
Mysql行转列,列转行----存储过程实现
最新推荐文章于 2025-03-02 21:45:49 发布