Mysql行转列
来源:互联网 发布:淘宝刷单被发现 编辑:程序博客网 时间:2024/06/06 04:12
准备表数据
CREATE TABLE test_user ( name varchar(50) DEFAULT NULL, subject varchar(50) DEFAULT NULL, score int(11) DEFAULT NULL);insert into test_user values('zhangsan' , 'chinese' , 10),('zhangsan' , 'math' , 20),('zhangsan' , 'english' , 30),('lily' , 'chinese' , 40),('lily' , 'math' , 50),('lily' , 'english' , 60),('mini' , 'chinese' , 70),('mini' , 'math' , 80),('mini' , 'english' , 90);select * from test_user
行转列
select name, max(IF(subject = 'chinese',score,0)) as 'chinese', max(IF(subject = 'math',score,0)) as 'math', max(IF(subject = 'english',score,0)) as 'english', sum(score) as'total'from test_usergroup by name
分析执行计划:
1、对表中数据根据name进行分组
2、对分组后的数据,进行处理。
0 0
- mysql 行转列
- mysql 行转列
- MySQL行转列
- mysql 行转列
- Mysql 行转列
- Mysql行转列
- mysql 行转列
- mysql 行转列
- mysql 行转列
- mysql 行转列
- Mysql 行转列
- mysql 行转列
- mysql 行转列
- mysql 行转列
- mysql 行转列
- Mysql行转列
- mysql行转列
- mysql 行转列
- Codeforces Round #289 (Div. 2, ACM ICPC Rules)
- opencv人脸识别总结1
- struts2核心(二):xwork/Container/bean/inject
- Spark 1.2 Standalone Mode 单机安装
- (二)Junit单元测试
- Mysql行转列
- ZOJ 2109 FatMouse's Trade(贪心)
- Canny边缘检测(转)
- 关于mac上Android Studio的安装步骤以及遇到的问题
- Mac Spotlight index error
- easyui combobox 本地数据实现输入中文拼音简码过滤数据
- PEP8 —— Python 的编程规范
- 解析PHP对象注入漏洞
- OpenFire源码学习之二十三:关于消息的优化处理