sql备份

本文详细介绍了使用SQL进行数据处理的方法,包括从教学站点表中选择特定字段,以及从收费记录表中按学校学号汇总可收费金额,并将结果按学号和类型排序。通过实际案例展示了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 

 

转载于:https://www.cnblogs.com/chenze-Index/p/10420047.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值