有什么办法给数据集汇总解决方法
有什么办法给数据集汇总
------解决方案--------------------
不好做,最好在@SelectResult里直接统计
------解决方案--------------------
改 @SelectResult.
------解决方案--------------------
- SQL code
如exec(@SelectResult) --这里面的列的个数是不固定的,有是会3列,有时会四列.列的个数是未知. 如exec(@SelectResult)这时的结果是这样 1 4.5 6 2 2.1 3 我想把上面的数据汇总一下. 结果为 1 4.5 6 2 2.1 3 3 6.6 9
------解决方案--------------------
不好做,最好在@SelectResult里直接统计
------解决方案--------------------
改 @SelectResult.
------解决方案--------------------
- SQL code
create table t ( id int, num int ) insert into t select 1,5 union all select 2,6 declare @tab table ( id int, num int ) insert into @tab select * from t union all select SUM(ID),SUM(num) from t select * from @tab --drop table t
------解决方案--------------------
- SQL code
set @SelectResult='select a,'+@auto+',c from tb union all select max(a)+1,sum(' +REPLACE(@auto,',','),sum(')+'),max(c) from tb'