Oracle的 简单行转列
应个报表要求做个
时间 双色球, 胜负彩。。。。。
200905 销量 销量
200906 销量 销量
200907 销量 销量
200908 销量 销量
一个SQL 语句得到结果是:
f_yearmonth, lot_name,money
200905 双色球 50
200905 胜负彩 100
200906 双色球 60
200906 胜负彩 70
Select f_yearmonth,
Max(decode(f_lotname,'双色球',f_money,0)) As "双色球",
Max(decode(f_lotname,'福彩3D',f_money,0)) as "福彩3D",
Max(decode(f_lotname,'胜负彩',f_money,0)) as "胜负彩",
Max(decode(f_lotname,'时时彩',f_money,0)) as "时时彩",
Max(decode(f_lotname,'时时乐',f_money,0)) as "时时乐",
from
t_tmp_test_A
Group By f_yearmonth
Order By f_yearmonth
关键语句:
Max(decode(f_lotname,'双色球',f_money,0)) As "双色球",
Group By f_yearmonth
应为 按时间重组只有一条,并且只有一条数据: 200905 双色球 50
那么 用MAX取一条数据 就是50
decode 意思说 如果是‘双色球’ 取对应的f_money 并且放在 命名为 "双色球"的 列上。
很显然 这列是固定!
相关文档:
1、对象类型规范
创建对象类型规范的语法如下
CREATE [OR REPLACE] TYPE [schema.] type_name
[AUTHID {CURRENT_USER|DEFINER}] AS OBJECT (
Attribute1 datatype,
[attribute2 datatype,…]
[method 1]
[method 2]);
/
其中AUTHID指示将来执行该方法时, ......
1 . set database to archivelog mode
Sql代码
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE&n ......
This article shows how Oracle's Heterogeneous Services can be configured to allow a database to connect to a Microsoft Access database using standard databases links. The method described can be used to connect to MS-Access from about any platform - Unix/ Linux or Windows.
MS-Access 2003 and Orac ......
在一般的PL/SQL程序开发中,可以使用SQL的DML语句和事务控制语句,但是DDL语句及会话语句却不能在PL/SQL中直接使用,要想实现在PL/SQL中使用DDL语句及会话控制语句,可以通过动态SQL来实现。
所谓动态SQL是指在PL/SQL块编译时SQL语句是不确定的,例如根据用户输入参数的不同而 ......