代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
PLSQL
】
Oracle行转列
作者:
Dezai.CN
/ 发布于
2011/12/28
/
1802
<div>create table pivot( pivot_id number(9) not null, year char(4) not null, quarter char(1) not null, amount number(9,2) not null, constraint pivot_pk primary key(pivot_id), constraint pivot_ak unique (year,quarter) );</div> <div>/*insert test data*/ insert into pivot (pivot_id,year,quarter,amount) values(1,'2008','1',2085.45); insert into pivot (pivot_id,year,quarter,amount) values(2,'2008','2',5899.90); insert into pivot (pivot_id,year,quarter,amount) values(3,'2008','3',46899.23); insert into pivot (pivot_id,year,quarter,amount) values(4,'2008','4',554.55);</div> <div>insert into pivot (pivot_id,year,quarter,amount) values(5,'2007','1',69878.23); insert into pivot (pivot_id,year,quarter,amount) values(6,'2007','2',5568.78); insert into pivot (pivot_id,year,quarter,amount) values(7,'2007','3',4566.00); insert into pivot (pivot_id,year,quarter,amount) values(8,'2007','4',56658.55);</div> <div>insert into pivot (pivot_id,year,quarter,amount) values(9,'2006','1',3565.36); insert into pivot (pivot_id,year,quarter,amount) values(10,'2006','2',4789.56); insert into pivot (pivot_id,year,quarter,amount) values(11,'2006','3',9865.78); insert into pivot (pivot_id,year,quarter,amount) values(12,'2006','4',469852.36);</div> <div>select year, (case quarter when '1' then amount else 0 end) as Q1, (case quarter when '2' then amount else 0 end) as Q2, (case quarter when '3' then amount else 0 end) as Q3, (case quarter when '4' then amount else 0 end) as Q4 from pivot;</div> <div>select year, sum(case quarter when '1' then amount else 0 end) as Q1, sum(case quarter when '2' then amount else 0 end) as Q2, sum(case quarter when '3' then amount else 0 end) as Q3, sum(case quarter when '4' then amount else 0 end) as Q4 from pivot group by year;</div> <div>select p.*, (Q1+Q2+q3+Q4) as total from( select year, sum(case quarter when '1' then amount else 0 end) as Q1, sum(case quarter when '2' then amount else 0 end) as Q2, sum(case quarter when '3' then amount else 0 end) as Q3, sum(case quarter when '4' then amount else 0 end) as Q4 from pivot group by year )p;</div> <div></div>
试试其它关键字
行转列
同语言下
.
查看某张表的表结构
.
oracle 集合操作
.
for 循环中倒序 用reverse
.
Oracle 临时表空间收缩
.
查看session及其对应运行的sql
.
Oracle常用查看表结构命令
.
Oracle Connect By Prior用法(实现递归查询)
.
重置排序 SEQUENCE
.
创建一个trigger
.
批量替换字段中的字符
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
Dezai.CN
贡献的其它代码
(
4037
)
.
多线程Socket服务器模块
.
生成随机密码
.
清除浮动样式
.
弹出窗口居中
.
抓取url的函数
.
使用base HTTP验证
.
div模拟iframe嵌入效果
.
通过header转向的方法
.
Session操作类
.
执行sqlite输入插入操作后获得自动编号的ID
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3