oracle 列转行
来源:互联网 发布:跟我学plc编程 编辑:程序博客网 时间:2024/06/08 05:48
oracle 列转行
@URL:http://www.cnblogs.com/Mr_JinRui/archive/2011/05/27/2060109.html
1.新建一个名为TEST表
2.向TEST表中添加数据
INSERT INTO TEST(STUDENT,COURSE,SCORE)
select '张三','语文',78 from dual union
select '张三','数学',87 from dual union
select '张三','英语',82 from dual union
select '张三','物理',90 from dual union
select '李四','语文',65 from dual union
select '李四','数学',77 from dual union
select '李四','英语',65 from dual union
select '李四','物理',85 from dual
表数据如下:
3.列转行
方法··1:
select
Student,
sum(decode(Course, '数学', Score)) 数学,
sum(decode(Course, '物理', Score)) 物理,
sum(decode(Course, '英语', Score)) 英语,
sum(decode(Course, '语文', Score)) 语文
from
TEST
group by Student
方法··2:
select
Student,
sum(case Course when '数学' then Score else null end) 数学,
sum(case Course when '物理' then Score else null end) 物理,
sum(case Course when '英语' then Score else null end) 英语,
sum(case Course when '语文' then Score else null end) 语文
from
TEST
group by Student
效果如下:
注:sum是求和的意思;比如说里面记录里面有两条张三,列转行显示的结果就会是两个张三的结果之和。
- ORACLE 列转行
- 行转列.列转行 oracle
- Oracle列转行
- oracle 行转列,列转行
- 【ORACLE】行转列,列转行
- oracle 列转行
- oracle 行转列 列转行
- oracle 行转列,列转行
- ORACLE sql 列转行
- oracle列转行
- oracle 行转列 列转行
- oracle 列转行
- oracle 列转行
- oracle行转列、列转行
- oracle 列转行
- oracle 行转列 列转行
- oracle 行转列 列转行
- oracle 列转行
- 关于get_magic_quotes_gpc()函数
- Java日期类的综合使用更新中~
- 更新android sdk manager 没安装完,结果eclipse里面安装的adt没了
- hibernate.jdbc.fetch_size 和 hibernate.jdbc.batch_size
- xhtml
- oracle 列转行
- 在Fragmet中应用Theme
- SSIS64-bit计算机不能连接到oracle解决办法
- Qualcomm MSM8625 源码下载
- 硬盘的PIO模式和DMA模式
- js 闭包和匿名函数
- flex 给group填充背景图片、颜色
- Linux 下设置oracle 11.2 数据库自动启动
- PHP连接MYSQL数据库通用类