Advertisement
Pandaaaa906

U8生产订单审核次数

May 3rd, 2023 (edited)
1,421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. with processed_wa as (
  2.  
  3.     SELECT
  4.     VoucherId,
  5.     VoucherType,
  6.     VoucherCode,
  7.     Action,
  8.     OperatorName,
  9.     OperationDate,
  10.     row_number() over(partition by VoucherID order by OperationDate asc) action_r
  11.  
  12.     from WFAudit wa with(nolock)
  13.     where wa.[VoucherType] = N'MO21'
  14.  
  15. ), filtered_wa as (
  16.     -- Action
  17.     -- 0 提交
  18.     -- 1 同意
  19.     -- 7 弃审
  20.     -- 5 撤销
  21.     -- 后面有5, 7都不要
  22.     SELECT
  23.     t1.*
  24.     FROM processed_wa t1
  25.  
  26.     where not EXISTS (
  27.         SELECT top 1 1 as ignored
  28.         FROM processed_wa t2
  29.         where t2.VoucherID = t1.VoucherID
  30.         AND t2.VoucherType = t1.VoucherType
  31.         AND t2.Action in (5, 7)
  32.       AND t2.action_r >= t1.action_r
  33.     )
  34.    
  35. )
  36.  
  37. SELECT
  38. -- *,
  39. -- count(*) over(partition by [VoucherId]) c
  40. count(*) c
  41. FROM filtered_wa
  42. WHERE VoucherType = 'MO21'
  43. AND filtered_wa.Action = 1
  44. AND [VoucherId] = 1000090696
  45. -- AND [VoucherId] = 1000129275
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement