/*正局级干部医疗费报销明细表sql脚本*/
select * from (
select a.社保编码,a.姓名,门诊医疗费,住院医疗费,基本医疗费,住院补充保险三报销,公务员住院医疗补助,正局级医疗补助 from (
select toa_3879_20150507160842 as 社保编码,
toa_8683_20150507160906 as 姓名,
sum(toa_1253_20150507161405) as 门诊医疗费,
sum(toa_4899_20150507161746) as 基本医疗费
from toa_wd_8892
group by toa_3879_20150507160842, toa_8683_20150507160906
) as a
left join (
select toa_6605_20150507170717 as 社保编码,
toa_0180_20150507170753 as 姓名,
sum(toa_8625_20150507170834) as 住院医疗费,
sum(toa_3504_20150507173835) as 住院补充保险三报销,
sum(toa_1508_20150507173910) as 公务员住院医疗补助,
sum(toa_3030_20150507173930) as 正局级医疗补助
from toa_wd_8893
group by toa_6605_20150507170717, toa_0180_20150507170753
) as b
on a.社保编码=b.社保编码
union
select b.社保编码,b.姓名,门诊医疗费,住院医疗费,基本医疗费,住院补充保险三报销,公务员住院医疗补助,正局级医疗补助 from (
select toa_3879_20150507160842 as 社保编码,
toa_8683_20150507160906 as 姓名,
sum(toa_1253_20150507161405) as 门诊医疗费,
sum(toa_4899_20150507161746) as 基本医疗费
from toa_wd_8892
group by toa_3879_20150507160842, toa_8683_20150507160906
) as a
right join (
select toa_6605_20150507170717 as 社保编码,
toa_0180_20150507170753 as 姓名,
sum(toa_8625_20150507170834) as 住院医疗费,
sum(toa_3504_20150507173835) as 住院补充保险三报销,
sum(toa_1508_20150507173910) as 公务员住院医疗补助,
sum(toa_3030_20150507173930) as 正局级医疗补助
from toa_wd_8893
group by toa_6605_20150507170717, toa_0180_20150507170753
) as b
on a.社保编码=b.社保编码) as c limit 0,2;