我正在尝试为电子邮件线程创建一个 dbase 解决方案。当我收到一封电子邮件时.. 我想知道这封电子邮件是否属于现有线程。
所以我匹配主题即主题='cool bro'匹配're:cool bro'
我也想匹配发送者和接收者对
IE
(sender = 'A@gmail.com' and receiver = 'B@gmail.com')
或者
(sender ='B@gmail.com' and receiver = 'A@gmail.com')
对于那些确切的情况..这个查询工作正常(在这里查看更多细节):
(SELECT COUNT(search_email.threadID) FROM search_email
WHERE search_email.subject MATCH '%query%' AND
(
(search_email.sender = '%sender' AND search_email.tos = '%receiver%')
OR
(search_email.sender = '%receiver%' AND search_email.tos = '%sender%')
)
问题是当您遇到这样的情况时:
(sender = 'Amanda Collins A@gmail.com' and receiver = 'B@gmail.com')
或者
(sender ='Billy Bob B@gmail.com' and receiver = 'A@gmail.com')
显然.. MATCH 子句(或一些正则表达式或其他东西)在这里是有序的..
问题是 sqllite不允许 MATCH
使用OR
:UNION
而是需要 a ..
但我想不出一种方法将上述语句转换为具有以下内容的语句UNION/INTERSECT
:
SELECT * FROM search_email WHERE
search_email.subject MATCH '%query%' INTERSECT SELECT * FROM
(SELECT * FROM (SELECT * FROM search_email WHERE
search_email.sender MATCH '%sender%'
INTERSECT SELECT * FROM search_email WHERE search_email.tos MATCH '%receiver%' )
UNION
SELECT * FROM( SELECT * FROM search_email WHERE search_email.sender MATCH '%sender%'
INTERSECT SELECT * FROM search_email WHERE search_email.tos MATCH '%receiver%'))
有任何想法吗?
更新:
似乎答案只是将第intersect
一个更改为union
:
SELECT * FROM search_email WHERE
search_email.subject MATCH '%query%' UNION SELECT * FROM
(SELECT * FROM (SELECT * FROM search_email WHERE
search_email.sender MATCH '%sender%'
INTERSECT SELECT * FROM search_email WHERE search_email.tos MATCH '%receiver%' )
UNION
SELECT * FROM( SELECT * FROM search_email WHERE search_email.sender MATCH '%sender%'
INTERSECT SELECT * FROM search_email WHERE search_email.tos MATCH '%receiver%'))
但是这个解决方案似乎效率很低..mysql编译器需要一段时间才能弄清楚..有没有更有效的方法?