select sum(A.)
FROM A
where A.qx_riqi between to_date('2007-8-1', 'yyyy-mm-dd') and
to_date('2007-8-30', 'yyyy-mm-dd')
and A.id ='0075'
union
SELECT SUM(B.piao_)
From B
WHERE B.piao_riqi between to_date('2007-8-1', 'yyyy-mm-dd') and
to_date('2007-8-30', 'yyyy-mm-dd')
and B.id ='0075'
所得的结果是
------------
sum(A.)
1: 0.1
2: 0.9
--------
实际上我想要的结果是
sum(A.) sum(b.)
1: 0.1 0.9
请问怎样修改这个sql语句呢?两个select语句的时间参数,和id是一样的
FROM A
where A.qx_riqi between to_date('2007-8-1', 'yyyy-mm-dd') and
to_date('2007-8-30', 'yyyy-mm-dd')
and A.id ='0075'
union
SELECT SUM(B.piao_)
From B
WHERE B.piao_riqi between to_date('2007-8-1', 'yyyy-mm-dd') and
to_date('2007-8-30', 'yyyy-mm-dd')
and B.id ='0075'
所得的结果是
------------
sum(A.)
1: 0.1
2: 0.9
--------
实际上我想要的结果是
sum(A.) sum(b.)
1: 0.1 0.9
请问怎样修改这个sql语句呢?两个select语句的时间参数,和id是一样的
解决方案 »
- 创建临时表
- 如何查看oracle自定义数据类型的定义?
- form开发如何处理并发?????????
- 关联子查询
- oracle用sql语句导出csv
- 关于oracle触发器的一个问题 在线等
- 2000 ad server下安装oracle 9时要求插入磁盘 2?怎么解决?
- Oracle中的Sequences怎么操作它?
- 大家讨论一下滥用触发器会给系统带来什么危害
- 请问如何在PL/SQL中创建一个新的Transaction,并且使用这个Transaction,有分,在线等待QQ:1720120 mail:[email protected]
- 取得Oracle字段类型的问题!!!!!
- 请教一个增量备份的方法
from (select sum(A.)
FROM A
where A.qx_riqi between to_date('2007-8-1', 'yyyy-mm-dd') and
to_date('2007-8-30', 'yyyy-mm-dd')
and A.id = '0075'),
(SELECT SUM(B.piao_)
From B
WHERE B.piao_riqi between to_date('2007-8-1', 'yyyy-mm-dd') and
to_date('2007-8-30', 'yyyy-mm-dd')
and B.id = '0075');
select decode(flag,'a',sum_val,0) val1,
decode(flag,'b',sum_val,0) val2
from (
select sum(A.) sum_val ,'a' flag
FROM A
where A.qx_riqi between to_date('2007-8-1', 'yyyy-mm-dd') and
to_date('2007-8-30', 'yyyy-mm-dd')
and A.id ='0075'
union all
SELECT SUM(B.piao_) sum_val, 'b' flag
From B
WHERE B.piao_riqi between to_date('2007-8-1', 'yyyy-mm-dd') and
to_date('2007-8-30', 'yyyy-mm-dd')
and B.id ='0075'
)
val1 val2
0.07 0
0 0.2
枫叶的方法倒是可行,继续等待其他方法
FROM A
where A.qx_riqi between to_date('2007-8-1', 'yyyy-mm-dd') and
to_date('2007-8-30', 'yyyy-mm-dd')
and A.id ='0075') as sum(A.),
(SELECT SUM(B.piao_)
From B
WHERE B.piao_riqi between to_date('2007-8-1', 'yyyy-mm-dd') and
to_date('2007-8-30', 'yyyy-mm-dd')
and B.id ='0075') as SUM(B.piao_) from dual