【发布时间】:2017-08-30 11:50:49
【问题描述】:
我有表 Customer_AJ(客户 varchar,项目编号,购买日期时间),我有两个表,其中有 Sucess 和 Failure,我想要该客户在接下来的 30 分钟内没有成功的所有失败。
我使用 Not exist 进行了尝试,但它在 hashMatch 处循环(正如我在 queryplan 中看到的那样,我正在附加查询和执行计划的屏幕截图 ..
with Failure as (
select * from [dbo].[Customer_AJ] where item in ( 20, 34, 35, 36, 37, 47, 53, 54 )
) ,
success as (
select * from Customer_AJ where Item in ( 1, 3, 40, 42, 43, 5 )
) ,
final as (
select f.customer, f.item,f.purchase from Failure f left outer join success s
on f.customer = s.customer and DATEDIFF( minute , f.purchase , s.purchase ) between 0 and 30
where s.customer is NULL
)
select * from final
【问题讨论】:
-
不是实时查询统计信息的屏幕截图,而是通过实际执行计划 XML 到 brentozar.com/pastetheplan 并将链接添加到您的问题。
标签: sql-server azure indexing query-optimization azure-sql-database