select ta.票据号,ta.姓名, tb.姓名, ta.金额
from
(select 票据号,姓名,金额 from a where 买卖 = '买')ta ,
(select 票据号,姓名,金额 from a where 买卖 = '卖')tb
where ta.票据号 = tb.票据号 and ta.金额 = tb.金额
select t.票据号,
max( t.买方姓名) as 买方姓名,
max( t.卖方姓名) as 卖方姓名,
t.金额
from
(select a1.票据号,
decode(a1.买卖,'买'a.姓名,null) as 买方姓名,
decode(a1.买卖,'卖'a.姓名,null) as 卖方姓名,
a1.金额
from 表 a1,表 a2
on a1.票据号 = a2.票据) t
group by t.票据号
order by t.票据号