我有一个表格中的单词(该表格被称为token
),每个单词都是表格中的一行。我想在结果中检索相邻的单词。如何加快这种类型的查询?
例子:My name is Renato
必须返回:
My | name
name | is
is | Renato
下面的查询工作,但速度很慢。 textblockid
确定该单词所属的文本,sentence
是文本块中的句子计数(但此刻该值全为1),position
属性确定单词的顺序。
select w1.text,w2.text
from token as w1,
(select textblockid,sentence,position,text from token
order by textblockid,sentence,position) as w2
where w1.textblockid = w2.textblockid
and w1.sentence = w2.sentence
and w1.position = w2.position - 1
有没有更好/更快的方法来做到这一点?
子选择的目的是什么?有没有理由不能用普通的内连接来做到这一点? – SingleNegationElimination
问题1:您不必要地在子查询中排序结果。问题2:您正在加入WHERE子句中的表而不是JOIN子句。 (不知道这是否会影响性能,但至少令人困惑。) – Keith