具体的交叉SQL语句写法: select a.part_no,a.part_name, --sum(b.cost) sum(case when b.cost_id = ''''100'''' then b.cost else 0 end) as cost_100, sum(case when b.cost_id = ''''200'''' then b.cost else 0 end) as cost_200, sum(case when b.cost_id = ''''300'''' then b.cost else 0 end) as cost_300, sum(case when b.cost_id = ''''321'''' then b.cost else 0 end) as cost_321
from test_part_cost_tab a,test_part_cost_dt_tab b where a.part_no = b.part_no group by a.part_no,a.part_name
PS: 若主表有资料,从表没有资料时,交叉后会没有相应的资料 解决办法是在WHERE条件里用外连接 where a.part_no = b.part_no(+)