首页 > 解决方案 > 使用 Distinct 的语句的 SQL 调优(优化)

问题描述

我有一个运行速度非常慢的 SQL 语句,我想知道是否有更好的方法来编写它。也许使用 WHERE EXISTS 而不是 DISTINCT?我不确定。谢谢你。

SELECT distinct
b.ClientID,
b.FillDate as 'Fill_Date', 
b.MEDNbr as 'MED'
FROM
  [MedDB].[dbo].[Claim] b
  LEFT JOIN [MedDB].[dbo].[Store] c
  on b.StoreID = c.StoreID
  LEFT JOIN [MedDB].[dbo].[StoreGroup] d
  on c.StoreGroupID = d.StoreGroupID 
  left join [MedDB].dbo.[carrier] e
  on b.carrierId = e.carrierId
  left outer join [MedDB].dbo.[CarrierGroupCarrier] f
  on b.carrierID = f.carrierId
  left join [MedDB].dbo.[CarrierGroup] g
  on f.CarrierGroupId = g.CarrierGroupId

  WHERE
  b.MEDNbr = 1
  and b.CloseDate is NULL 
  and b. OpenClaimAmt Not In (0, -0.07, -0.10, 0.03, 0.05, 0.06, 0.12, 0.13, 0.26) )x;

标签: sqlsql-server-2012query-performance

解决方案


推荐阅读