
上QQ阅读APP看书,第一时间看更新
2.2.3 汇总部分字段全部数据
在select语句中,星号(*)表示全部字段,如果要汇总指定字段的数据,则需要列出具体字段名称了,参考如下。
select 字段1,字段2,字段3,……,字段n from [表$]
图2-38的示例数据是6个月的工资表中,要求将每个人的个税、社保和公积金合并到一个工作表。

图2-38 示例数据2
此时,SQL语句如下,汇总结果如图2-39所示。
select 月份,姓名,合同类型,个人所得税,社保金,公积金 from[1月$] union all select 月份,姓名,合同类型,个人所得税,社保金,公积金 from[2月$] union all select 月份,姓名,合同类型,个人所得税,社保金,公积金 from[3月$] union all select 月份,姓名,合同类型,个人所得税,社保金,公积金 from[4月$] union all select 月份,姓名,合同类型,个人所得税,社保金,公积金 from[5月$] union all select 月份,姓名,合同类型,个人所得税,社保金,公积金 from[6月$]

图2-39 汇总结果2