select cast(Address as varchar(6)) as Address,cast(CommercialType as varchar(6)) as CommercialType,EnterAmount,AccessAmount,OnlineAmount,Previousonline from #Result
union
select '合计' as Address ,'' as CommercialType,sum(EnterAmount) as CommercialType,sum(AccessAmount) as AccessAmount,sum(OnlineAmount) as OnlineAmount,sum(Previousonline) as Previousonline
from #Result where
address=@Address or @Address=''
and CommercialType=@CommercialType or @CommercialType=''
from #Result where
address=@Address or @Address=''
and CommercialType=@CommercialType or @CommercialType=''
本文介绍了一种使用SQL进行复杂汇总查询的方法,通过具体实例展示了如何将不同来源的数据整合并进行有效的统计分析。此方法适用于需要从多个角度审视业务数据的情况。
5137

被折叠的 条评论
为什么被折叠?



