存储过程 每15分钟分配一个区间 并相加

110 篇文章 0 订阅
30 篇文章 0 订阅
   ALTER proc [dbo].[sp_hyfx_SoldOutDistributiones] 
(@thedate bigint)
as
begin
--   create table #houres 
--(houres int )
--declare @i int 
--set @i=1
--while @i<=24
--begin 
--insert #houres values (@i-1)
--set @i =@i+1
--end 


select datepart( hour , OperationDate ) as houres, datepart( minute , OperationDate ) as minutess,AuctionNum,  OperationDate ,thedate into #hhh from   hyfx_SoldOutDistribution  where thedate=@thedate
  
  select '1-15' AS times , houres ,sum(AuctionNum) as AuctionNum into #tb1   from #hhh where thedate=@thedate AND MINUTESS  BETWEEN 1 AND 15 group by houres 
  UNION
  select '16-30' AS times , houres ,sum(AuctionNum) as AuctionNum   from #hhh where thedate=@thedate AND MINUTESS  BETWEEN 16 AND 30 group by houres 
   UNION
   select '30-45' AS times , houres ,sum(AuctionNum) as AuctionNum  from #hhh where thedate=@thedate AND MINUTESS  BETWEEN 30 AND 45 group by houres 
      UNION
   select '45-60' AS times , houres ,sum(AuctionNum) as AuctionNum  from #hhh where thedate=@thedate AND MINUTESS  BETWEEN 45 AND 60 group by houres 
  --   select T.houres ,cast( isnull( a.AuctionNum ,0) as varchar)  +'+' +cast ( isnull(b.AuctionNum ,0) as varchar)+'+' +cast ( isnull(c.AuctionNum ,0) as varchar)+'+' +cast ( isnull(d.AuctionNum ,0) as varchar)  as section
--from #houres t left join  #tb1 a  on  t.houres=a.houres and a.times ='1-15'  left join #tb1 b on t.houres =b.houres and b.times='16-30' left join #tb1 c on  t.houres=c.houres and c.times='30-45' left join #tb1 d on  t.houres=d.houres
--and d.times='45-60'




   select distinct a.houres ,cast( isnull( a.AuctionNum ,0) as varchar)  +'+' +cast ( isnull(b.AuctionNum ,0) as varchar)+'+' +cast ( isnull(c.AuctionNum ,0) as varchar)+'+' +cast ( isnull(d.AuctionNum ,0) as varchar)  as section
into #num from   #tb1 a   left join #tb1 b on a.houres =b.houres and b.times='16-30' left join #tb1 c on  a.houres=c.houres and c.times='30-45' left join #tb1 d on  a.houres=d.houres 
and d.times='45-60'  and a.times ='1-15'  
  select distinct houres ,sum(AuctionNum) as AuctionNumsum into #ber  from #hhh group by houres 
select distinct n.houres,n.section,b.AuctionNumsum from #num n,#ber b where n.houres=b.houres
  --select distinct a.houres ,cast( a.AuctionNum as varchar)  +'+' +cast (b.AuctionNum as varchar)+'+' +cast (c.AuctionNum as varchar) +'+' +cast (d.AuctionNum as varchar)   from #tb1 a  ,#tb1 b ,#tb1 c,#tb1 d where a.houres =b.houres and a.houres=c.houres and a.houres=d.houres and a.times ='1-15' and b.times ='16-30' and c.times ='30-45' and d.times ='45-60'
 
  end;


     exec sp_hyfx_SoldOutDistributiones 20171018
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值