请问excel表格的透视和转置怎么 *** 作, 谢谢 有什么意义

请问excel表格的透视和转置怎么 *** 作, 谢谢 有什么意义,第1张

数据透视表和数据透视图 (数据透视图:提供交互式数据分析的图表,与数据透视表类似。可以更改数据的视图,查看不同级别的明细数据,或通过拖动字段和显示或隐藏字段中的项来重新组织图表的布局。)提供了多种计算方式。数据字段 (数据字段:源数据清单、表或数据库中的字段,其中包含在数据透视表或数据透视图中汇总的数据。数据字段通常包含数字型数据,如统计或销售数量。)用汇总函数 (汇总函数:是一种计算类型,用于在数据透视表或合并计算表中合并源数据,或在列表或数据库中插入自动分类汇总。汇总函数的例子包括 Sum、Count 和 Average。)来合并基本源数据 (源数据:用于创建数据透视表或数据透视图的数据清单或表。源数据可以来自 Excel 数据清单或区域、外部数据库或多维数据集,或者另一张数据透视表。)中的数值。还可用自定义计算 (自定义计算:用数据透视表的数据区域中的其他单元格值对数据区域中的值进行汇总的方法。使用数据字段的“数据透视表字段”对话中的“数据显示方式”列表可创建自定义计算。)比较数据值或添加使用报表元素或其他工作表数据的公式。

你可以用复制数据库的方法,然后在另一台电脑上通过“附加数据库”的方法完成。但我也同意1楼的看法,既,导入/导出其实更简单。你觉得复杂可能是你没理解如何去做,其实很简单。只要选择好源数据库和目标数据库,数据复制就完成了。

静态脚本:
select '收入' as 项目
, case when 项目='一厂本月' then 收入 else null end as 一厂本月
, case when 项目='一厂本年' then 收入 else null end as 一厂本年
, case when 项目='二厂本月' then 收入 else null end as 二厂本月
, case when 项目='二厂本年' then 收入 else null end as 二厂本年
, case when 项目='三厂本月' then 收入 else null end as 三厂本月
, case when 项目='三厂本年' then 收入 else null end as 三厂本年
from 表名
union all
select '成本' as 项目
, case when 项目='一厂本月' then 成本 else null end as 一厂本月
, case when 项目='一厂本年' then 成本 else null end as 一厂本年
, case when 项目='二厂本月' then 成本 else null end as 二厂本月
, case when 项目='二厂本年' then 成本 else null end as 二厂本年
, case when 项目='三厂本月' then 成本 else null end as 三厂本月
, case when 项目='三厂本年' then 成本 else null end as 三厂本年
from 表名
union all
select '其他费用' as 项目
, case when 项目='一厂本月' then 其他费用 else null end as 一厂本月
, case when 项目='一厂本年' then 其他费用 else null end as 一厂本年
, case when 项目='二厂本月' then 其他费用 else null end as 二厂本月
, case when 项目='二厂本年' then 其他费用 else null end as 二厂本年
, case when 项目='三厂本月' then 其他费用 else null end as 三厂本月
, case when 项目='三厂本年' then 其他费用 else null end as 三厂本年
from 表名
union all
select '毛利' as 项目
, case when 项目='一厂本月' then 毛利 else null end as 一厂本月
, case when 项目='一厂本年' then 毛利 else null end as 一厂本年
, case when 项目='二厂本月' then 毛利 else null end as 二厂本月
, case when 项目='二厂本年' then 毛利 else null end as 二厂本年
, case when 项目='三厂本月' then 毛利 else null end as 三厂本月
, case when 项目='三厂本年' then 毛利 else null end as 三厂本年
from 表名
改动态脚本(只改项目,即改原表行不定,列数目固定):
declare @sql nvarchar(max)
set @sql=''
set @sql=@sql+'
select ''收入'' as 项目
'
select @sql=@sql+', case when 项目='''+项目+''' then 收入 else null end as '+项目
from 表名
set @sql=@sql+'
from 表名
'
set @sql=@sql+'union all
select ''成本'' as 项目
'
select @sql=@sql+', case when 项目='''+项目+''' then 成本 else null end as '+项目
from 表名
set @sql=@sql+'
from 表名
'
set @sql=@sql+'union all
select ''其他费用'' as 项目
'
select @sql=@sql+', case when 项目='''+项目+''' then 其他费用 else null end as '+项目
from 表名
set @sql=@sql+'
from 表名
'
set @sql=@sql+'union all
select ''毛利'' as 项目
'
select @sql=@sql+', case when 项目='''+项目+''' then 毛利 else null end as '+项目
from 表名
set @sql=@sql+'
from 表名
'
exec sp_executesql @sql
改动态脚本(改原表行和列数目不固定,两层动态脚本,能实现但基本难读):
declare @sql nvarchar(max)
set @sql='declare @sql_in nvarchar(max)
set @sql_in='' '' '
set @sql=@sql+'select @sql_in=@sql_in+''union all
select ''''''+name+'''''' as 项目
'
select @sql=@sql+', case when 项目='''''+项目+''''' then ''+name+'' else null end as '+项目
from 表名
set @sql=@sql+'
from 表名
''
from syscolumns where id=(select id from sysobjects where name=''表名'')
order by colorder
set @sql_in=stuff(@sql_in,1,10,'''')
exec sp_executesql @sql_in
'
exec sp_executesql @sql


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/13373044.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-07-23
下一篇 2023-07-23

发表评论

登录后才能评论

评论列表(0条)

保存