我如何合并两个查询的结果

时间:2013-07-11 06:40:59

标签: sql select

以下是查询和操作,我如何合并这些查询并获得所需的结果

1

SELECT sum(rpl) AS rpl,decrip 
from COMM c, BOOK b
   WHERE b.bookid=c.parbookid and booktype='trading' 
   GROUP BY b.decrip 

O / P

RPL DECRIP 
55  RBC 
45  bny 

2

SELECT sum(estcomm) as commission,decrip 
from COMM c, BOOK b 
    WHERE b.bookid=c.parbookid and booktype='wash' 
    GROUP BY b.decrip

O / P

COMMISSION DECRIP 
2234       RBC 
2468       bny 

我如何获得输出

 
RPL COMMISSION DECRIP 
55  2234       RBC 
45  2468       bny 

2 个答案:

答案 0 :(得分:0)

这个怎么样?

SELECT sum(rpl) AS rpl, sum(estcomm) as commission,decrip 
from COMM c, BOOK b
   WHERE b.bookid=c.parbookid 
        and (booktype='trading' OR  booktype='wash)
   GROUP BY b.decrip 

答案 1 :(得分:0)

尝试这样的事情(假设booktypeBOOK表下的一列)

SELECT sum(c.rpl) AS rpl,sum(c.estcomm) as commission,b.decrip 
from COMM c
join BOOK b
on b.bookid=c.parbookid 
where b.booktype in('trading','wash') 
GROUP BY b.decrip