MySQL行转列
来源:互联网 发布:广电网络考试试题 编辑:程序博客网 时间:2024/06/08 19:48
存储过程实现行转列select name,sum( case subject when 'chinese' then score else 0 end) as 'chinese',sum( case subject when 'math' then score else 0 end) as 'math',sum( case subject when 'english' then score else 0 end) as 'english'from usergroup by name;
在写存储过程的时候遇到了两个问题,分别是关于游标和临时表。create procedure line_to_col()begin declare i int; declare _chinese int; declare _math int; declare _english int; declare _name varchar(10); declare test_cursor CURSOR for select name from user; select count(*) into i from user; CREATE TEMPORARY TABLE tmp_tab( name varchar(10), chinese_score int, math_socre int, english_score int); if i> 0 then open test_cursor; repeat fetch test_cursor into _name; select score into _chinese from user where subject = 'chinese' and name =_name; select score into _math from user where subject = 'math' and name =_name; select score into _english from user where subject = 'english' and name =_name; insert into tmp_tab values(_name,_chinese,_math,_english); set i=i-1; until i=0 end repeat; close test_cursor; end if; select DISTINCT * from tmp_tab; drop table tmp_tab;end
- mysql 行转列
- mysql 行转列
- MySQL行转列
- mysql 行转列
- Mysql 行转列
- Mysql行转列
- mysql 行转列
- mysql 行转列
- mysql 行转列
- mysql 行转列
- Mysql 行转列
- mysql 行转列
- mysql 行转列
- mysql 行转列
- mysql 行转列
- Mysql行转列
- mysql行转列
- mysql 行转列
- [smali 插桩] 添加判断系统语言的代码(以中文zh为例)
- [笔记]线性回归&梯度下降
- ubuntu下patch的制作和应用
- php要怎么学习的呢?如果学习php啊,其实,我感觉还真的有点难哦!
- java---面向对象vs面向过程,局部变量vs成员变量
- MySQL行转列
- MySQL中group_concat函数
- landsat 卫星波段组合以及envi下的展示
- 工具类之二:RegexpUtils
- java 的接口到底起什么作用
- 防止 zombie 程序產生(Z)
- 在eclipse中修改SVN的用户名和密码
- ADT对应SDK版本
- UIWebView数据自动检测开关