SELECT t1.*
FROM asterisk t1
WHERE EXISTS (SELECT * FROM asterisk t2
WHERE t2.id <> t1.id
AND t2.unique_id = t1.unique_id
AND t1.operator_dial = '203'
AND t1.event = 'Dial'
AND t2.event = 'Bridge'
AND NOT EXISTS (SELECT * FROM asterisk t3
WHERE t3.id <> t1.id
AND t2.unique_id = t3.unique_id
AND t1.operator_dial = '203'
AND t3.event = 'Unlink'))
ORDER BY date DESC
LIMIT 1
需要帮助以使其快速工作,这可能吗?我的脑袋准备爆炸,试图理解它应该做什么。(表有大约 5k 条记录)该查询的描述是:“看看是否有 Dial 事件,之后是 Bridge 事件,但没有 Unlink 事件”。