union all语句匹配和经历总结
在以往工作中,有社保局数据需要通过数据库复杂的查询的业务,以此为基地 深入研究了union all 语句的用法>>实际上采用多个查询结果集合,继而实行全并集的方式来汇总数据,让我对数据库语言的汇总进行了升华和理解,若是以后有此类样例和需求便能更好更快的整理思路,确定大致的方案,以便日后参考和编码.
SQL语句如下以及相关解释和意义.
此外,union all等同于mySql中的full join作用,加此一条作为日后参考
select sum(taR.CFCorSocSecAcct) as CFCorSocSecAcct, sum(taR.CFCorfundAcct) as CFCorfundAcct, sum(taR.FReceivableTotal) as FReceivableTotal,sum(taR.FPersonalTotal) as FPersonalTotal,sum(taR.FUnitTotal) as FUnitTotal, sum(taR.FUnitFund) as FUnitFund, sum(taR.FPersonalFund) as FPersonalFund,sum(taR.FSocPersonTotal) as FSocPersonTotal,sum(taR.FSocUnitTotal) as FSocUnitTotal,sum(S164) S164,sum(S166) S166,sum(S162) S162,sum(S168) S168,sum(S175) S175,sum(S176) S176,SUM(S173) S173,SUM(S174) S174,taR.perName as perName,taR.perNum as perNum , taR.adminName as adminName , sum(taR.CFSocSec) as CFSocSec,sum(taR.CFaccumFund) as CFaccumFund,sum(FSocPersonal1) as FSocPersonal1,sum(FItemPersonal1) as FItemPersonal1 from table
// FReceivableTotal应收合计,FPersonalTotal个人合计,FUnitTotal单位合计,
// FUnitFund公积金单位缴纳金,1
// FPersonalFund公积金个人缴纳金2,
// FSocPersonTotal个人社保合计,3
// FSocUnitTotal单位社保合计,4
// FPeriodYear统计年,FPeriodMonth统计月
// sbSql.append(" union all ")
// 并集1select 1;
总体架构是 Sql1 union all
Sql2 union all
Sql3 union all
Sql4
至此,总结完毕.