有人可以帮我弄清楚查询有什么问题吗?我收到“错误代码:1064 您的 SQL 语法有错误;” 尝试执行它时出错,但不明白为什么。
SELECT CASE WHEN WEEKDAY(h.createdDate) NOT IN (5,6) THEN (TIME_TO_SEC(EXTRACT(HOUR_MINUTE FROM h.nextCreatedDate)) - TIME_TO_SEC(EXTRACT(HOUR_MINUTE FROM h.CreatedDate))) / 60 / 24
WHEN WEEKDAY(h.createdDate) IN (5,6) THEN TIME_TO_SEC(EXTRACT(HOUR_MINUTE FROM h.nextCreatedDate)) /60 24
END AS t3,
h.CaseId, h.CreatedDate, h.nextCreatedDate, h.Field, h.NewValue, h.Status
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