select sum(A.mark)
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_mark)
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.mark)
1: 0.1
2: 0.9
--------
实际上我想要的结果是
sum(A.mark) sum(b.mark)
1: 0.1 0.9
请问怎样修改这个sql语句呢?两个select语句的时间参数,和id是一样的
------解决方案--------------------
这样写就可以了
select *
from (select sum(A.mark)
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_mark)
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 ');