我试图创建一个电子邮件线程一个dBASE解决方案。 当我收到一封电子邮件。我想知道,如果这封邮件属于现有的线程。
所以我匹配的主题即主题=“酷兄弟”匹配“重:酷兄弟”
和我也想发送器和接收器对匹配
即
(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')
显然..匹配条款(或某个正则表达式或财产以后)是为了在这里..
问题是,sqllite 不允许 MATCH
一起工作OR
:一个UNION
是不是需要..
但我不能想出一个办法,以上面的语句转换成具有声明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的编译器需要一段时间才能弄明白..有一个更有效的方法?