直接上题
:
有a表(虚构)
时间1 购买1 时间2 购买2
2001 10 2003 3
2004 3 2000 5
2003 5 2001 2
现在要进行统计得出如下结构:
时间 购买1 购买2
求解
不知道能不能解决
:
有a表(虚构)
时间1 购买1 时间2 购买2
2001 10 2003 3
2004 3 2000 5
2003 5 2001 2
现在要进行统计得出如下结构:
时间 购买1 购买2
求解
不知道能不能解决
解决方案 »
- 把查询的结果作为数据参数输出,创建过程后提示带警告
- 登陆数据库问题
- 查询表中Route这个字段的整列中数据是否有符合where Route = '路由2';前面怎么写?
- 请问这样一个PROCEDURE 怎么创建才算好?
- 这个占位符如何写?
- 启用oracle 归档模式出错!!
- 请教一个问题,我的程序中的select后的列名是根据不同情况变化的,但是我希望他们都能够按照列的顺序排序,oracle中有没有象informix中的
- 救命啊!long raw字段(实际存储的是文本内容)查询怎么做呀
- 如何捕获应用程序连接oracel的执行语句
- oracle 通过条件输出多条
- 无法解析连接描述符中指定的SID
- 新人求助
然后再加一点filter 条件
First,
create table test as select 时间1 时间,购买1, 购买2 from <表的名称>;
Second,
insert into test select 时间2,购买1, 购买2 from <表的名称>;Finally,
select * from test;
create table test(
t1 int,
g1 int,
t2 int,
g2 int
)
insert into test values(2001, 10, 2003, 3);
insert into test values(2004, 3, 2000, 5);
insert into test values(2003, 5, 2001, 2);select a.t1,a.g1,b.g2
from test a, test b
where a.t1 = b.t2(+)
union
select b.t2,a.g1,b.g2
from test b, test a
where b.t2 = a.t1(+)
SQL> with tb as(
2 select '2001' dt1,10 num1,'2003' dt2,3 num2 from dual union all
3 select '2004',3,'2000',5 from dual union all
4 select '2003',5,'2001',2 from dual)
5 select nvl(a.dt1,b.dt2) dt,nvl(a.num1,0),nvl(b.num2,0)
6 from tb a full join tb b
7 on a.dt1=b.dt2
8 order by dt
9 /
DT NVL(A.NUM1,0) NVL(B.NUM2,0)
---- ------------- -------------
2000 0 5
2001 10 2
2003 5 3
2004 3 0
select '2001' sj1,10 gm1,'2003' sj2,3 gm2 from dual
union all
select '2004',3,'2000',5 from dual
union all
select '2003',5,'2001',2 from dual
)
select sj1 "sj", sum(decode(kind, 1, gm1, 0)) "gm1", sum(decode(kind, 2, gm1, 0)) "gm2"
from (select sj1, gm1, '1' kind
from t
union all
select sj2, gm2, '2' from t)
group by sj1;
sj gm1 gm2
---- ---------- ----------
2000 0 5
2001 10 2
2003 5 3
2004 3 0