我们无法让这个简单的查询工作:
SELECT * FROM
(SELECT h.*, h.NewValue AS STATUS,
(SELECT h2.CreatedDate
FROM siebel_service_request_history h2
WHERE h2.Field = 'Status' AND h2.CreatedDate > h.CreatedDate AND
h2.SiebelID = h.SiebelID
ORDER BY h2.CreatedDate
LIMIT 1
) AS nextCreatedDate
FROM siebel_service_request_history h WHERE h.Field ='Status') h
GROUP BY h.SiebelID, h.Status
它适用于 grouping by SiebelID
(但速度很慢),并且如果我们添加 grouping by ,它会永远挂起Status
。但是我们需要在分组中包含两个字段才能获得我们想要的数据。
对于 salesforce_case_history 表,我们运行和工作的查询完全相同(它运行得非常快,准确地说,我们在两个表中的记录数大致相同(salesforce_case_history - -- 1159870 条记录 VS siebel_service_request_history - 1202865 条记录)):
SELECT * FROM (SELECT h.*, h.NewValue AS STATUS,
(SELECT h2.CreatedDate
FROM salesforce_case_history h2
WHERE h2.Field = 'Status' AND h2.CreatedDate > h.CreatedDate AND
h2.CaseId = h.CaseId
ORDER BY h2.CreatedDate
LIMIT 1
) AS nextCreatedDate
FROM salesforce_case_history h WHERE h.Field ='Status'
) h
GROUP BY h.CaseId, h.Status
siebel_service_request_history
我们还为内部子选择搜索创建了相同的复合索引,包括我们在 salesforce_case_history 上创建的三个字段 ( SiebelID
, CreatedDate
, ) 表。Field
我们尝试了几乎所有我们知道的东西,但不幸的是没有找到这个问题的根本问题。