sql server 前置填充

UPDATE  [perf_attr_stock].[dbo].[t_stock_quote]
SET 
AccuCashDivi = b.AccuCashDivi,
RatioAdjustingFactor = b.RatioAdjustingFactor,
AccuBonusShareRatio  = b.AccuBonusShareRatio
FROM
(
select   [stock_code]
      ,[stock_date]
	  ,tbb.ExDiviDate
	  ,tbb.nextdate
      ,tbb.[RatioAdjustingFactor] 
      ,tbb.[AccuCashDivi]  
      ,tbb.[AccuBonusShareRatio]    
  from [perf_attr_stock].[dbo].[t_stock_quote_20190702] tba  
  cross join 
	 (select SecuCode 
	   ,[ExDiviDate]  
	   ,isnull(LEAD([ExDiviDate]) over(PARTITION  BY a.InnerCode order by [ExDiviDate]),getdate()) nextdate
      ,[RatioAdjustingFactor] 
      ,[AccuCashDivi]  
      ,[AccuBonusShareRatio]  
		 from [juyuan_DB].[dbo].[QT_AdjustingFactor] a
		  inner join juyuan_db.dbo.SecuMain b 
		 on a.InnerCode = b.InnerCode and  b.SecuCategory='1' and b.SecuMarket in ('83','90')
		 ) tbb 
   where  tba.stock_code = tbb.SecuCode  
   and   tba.[stock_date]>=tbb.[ExDiviDate] and tba.[stock_date]

 

你可能感兴趣的:(数据库)