在EXCEL中如何转置行列数据

在EXCEL中如何转置行列数据,第1张

已excel2010版本为例,转置方法如下:

1、打开excel表格,有下面AB两列数据,想把它们转成行的;

2、首先全选这两列数据,然后点击复制,或者直接按Ctrl+C 复制;

3、然后在要复制到的地方,点击鼠标右键,再点击“选择性粘贴”,进入设置界面;

4、在“选择性粘贴”功能框里选择“数值”,“运算”选择无,选择“转置”,然后点下面的确定按钮;

5、点击确定后得到如下图所示的两行数据了,即成功的把列转置成了行,同理,把行转置成列也是一样的步骤。

declare @maxcount int

declare @i int

declare @sql nvarchar(max)

select @maxcount=max(C) from (select 采购商,count(*) C from table1 group by 采购商) a

print @maxcount

set @i=1

set @sql='select distinct 采购商,(select max(商品) from table1 b where b.采购商=a.采购商) 商品1'

while @i<@maxcount

begin

set @sql=@sql+', (select max(商品) from table1 b where b.采购商=a.采购商 and 商品 not in (select top '+ cast(@i as nvarchar(4))+' 商品 from table1 c where b.采购商=c.采购商 order by 商品 desc)) 商品' + cast(@i+1 as nvarchar(4))

set @i=@i+1

end

set @sql=@sql+' from table1 a'

exec(@sql)


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

原文地址: https://outofmemory.cn/sjk/10001630.html

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

发表评论

登录后才能评论

评论列表(0条)

保存