mysql横纵表转化_数据库MySQL横纵表相互转化操作实现⽅
本⽂实例讲述了MySQL横纵表相互转化操作实现⽅法。分享给⼤家供⼤家参考,具体如下:
matlab的figure函数用法先创建⼀个成绩表(纵表)
create table user_score
(
name varchar(20),
subjects varchar(20),
score int
);
insert into user_score(name,subjects,score) values('张三','语⽂',60);
insert into user_score(name,subjects,score) values('张三','数学',70);
dubberinsert into user_score(name,subjects,score) values('张三','英语',80);
mysql怎么读英语insert into user_score(name,subjects,score) values('李四','语⽂',90);
insert into user_score(name,subjects,score) values('李四','数学',100);
再创建⼀个成绩表(横表)
create table user_score2
(
name varchar(20),
yuwen int,
shuxue int,
yingyu int
);渐变美甲图片2017
insert into user_score2(name,yuwen,shuxue,yingyu) values('张三',60,70,80);
insert into user_score2(name,yuwen,shuxue,yingyu) values('李四',90,100,0);
纵表转横表
select name,sum(case subjects when '语⽂' then score else 0 end)
as '语⽂',sum(case subjects when '数学' then score else 0 end)
as '数学', sum(case subjects when '英语' then score else 0 end)
as '英语'from user_score group by name;
纵表转横表
SELECT name,'yuwen' AS subjects,yuwen AS score FROM user_score2 UNION ALL
SELECT name,'shuxue' AS subjects,shuxue AS score FROM user_score2 UNION ALL
json格式数据导入mysql
SELECT name,'yingyu' AS subjects,yingyu AS score FROM user_score2
ORDER BY name,subjects DESC;
更多关于MySQL相关内容感兴趣的读者可查看本站专题:《MySQL查询技巧⼤全》、《MySQL事务操作技巧汇总》、《MySQL存储过程技巧⼤全》、《MySQL数据库锁相关技巧汇总》及《MySQL常⽤函数⼤汇总》
vb是一种什么编程语言希望本⽂所述对⼤家MySQL数据库计有所帮助。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。