--第一步:根据系统编号.列.单价分组求和 select CLBH,DJ,sum(SL) as SL,sum(JE) as JE,Lie into #TempSZCMX from #ShouZhiCunMingXi group by Lie, CLBH , DJ order by Lie,CLBH --第二步:列转行,分组求和 insert into #TempLastResults SELECT YJ,EJ, MoJi=(CASE WHEN grouping(YJ) = 1 THEN '0'…