sql备份

SELECT id,Name FROM TeachSite GROUP BY id




select top 1000  1 as [type],SchoolRollID,ChargeableAmount  into #temp from ChargeRecord where bflag=1


select * from #temp  



select 2 as [type], SchoolRollID,SUM(ChargeableAmount) as xj
into #tempxj
 from #temp   group by SchoolRollID

 select 0 as  [typq], null as  SchoolRollID ,SUM(xj) as hj  into #temphj from #tempxj 


 select *  from #temp


insert  into #temp
 select * from #tempxj


insert  into #temp
 select * from #temphj


 select * from #temp order by SchoolRollID,[type] desc 
作者:chenze
出处:https://www.cnblogs.com/chenze-Index/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
如果文中有什么错误,欢迎指出。以免更多的人被误导。
原文地址:https://www.cnblogs.com/chenze-Index/p/10420047.html