删除不同粒度的事实表记录中重复的度量值数据的SQL语句

update vtronstaging.dbo.fact_t_purchasing
set 通知数量 = 0, 通知单号 =0  where 通知单ID is null

update vtronstaging.dbo.fact_t_purchasing
set 实际入库数量 = 0, 实际入库单价 = 0, 实际入库金额 = 0, 入库单号 = 0, 入库日期 = '01/01/2049' where 入库单ID is null


update vtronstaging.dbo.fact_t_purchasing
set 订货数量 = 0 , 采购金额 = 0
from vtronstaging.dbo.fact_t_purchasing t1
where [入库单号] <>
  (
 select top 1 [入库单号]
 from vtronstaging.dbo.fact_t_purchasing t2
 where t1.采购单ID = t2.采购单ID and t1.采购单分录ID = t2.采购单分录ID
 order by [入库单号] desc
  )

你可能感兴趣的:(sql语句)