case when then min()

ktecyv1j  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(602)

协助案件陈述的第二个阶段。我需要为下面的场景编码:如果有两个pcc=null的记录,那么选择具有最小值的providerfinaltier。它当前正在选择表的min providerfinaltier。

  1. <!-- language: lang-sql-->
  2. UPDATE spc
  3. SET ProviderTier = CASE WHEN (coalesce(spc.rulespecialtyid, spc.RenderingproviderspecialtyID) = mft.SpecialtyID and coalesce(spc.RulePCC,spc.PCC) = mft.PCC ) THEN ProviderFinalTier
  4. WHEN (coalesce(spc.rulespecialtyid, spc.RenderingproviderspecialtyID) = mft.SpecialtyID and mft.pcc is null)
  5. THEN (Select min(ProviderFinalTier) from Common.medicarefinaltiers where coalesce(spc.rulespecialtyid, spc.RenderingproviderspecialtyID) = mft.SpecialtyID and mft.pcc is null)
  6. ELSE 2 END
  7. from analysis.AnalysisMatchedClaims spc
  8. left join Compass_REPORTING.dbo.Payer p on p.Payer_Key = spc.PayerKey
  9. left join Common.medicarefinaltiers mft on /*mft.EmployerId = spc.EmployerId
  10. and */mft.ProviderID = spc.RenderingProviderId
  11. and mft.SpecialtyId = coalesce(spc.rulespecialtyid, spc.RenderingproviderspecialtyID)
  12. and mft.PayerGroup = p.Payer_Group
  13. WHERE spc.ProviderTier is null
  14. and (mft.pcc = coalesce(spc.RulePCC,spc.PCC) or mft.PCC is null)
  15. and spc.RuleClaimType = 'I'
xzv2uavs

xzv2uavs1#

在此子查询中:

  1. Select min(ProviderFinalTier)
  2. from Common.medicarefinaltiers
  3. where coalesce(spc.rulespecialtyid, spc.RenderingproviderspecialtyID) = mft.SpecialtyID
  4. and mft.pcc is null

你没有给表加别名 Common.medicarefinaltiers 有没有提到 mft 实际上是对外部联接表的引用 Common.medicarefinaltiers .
我认为应该为表提供一个别名,并在以下条件下使用该别名:

  1. Select min(m.ProviderFinalTier)
  2. from Common.medicarefinaltiers m
  3. where coalesce(spc.rulespecialtyid, spc.RenderingproviderspecialtyID) = m.SpecialtyID
  4. and m.pcc is null

相关问题