0

我使用这个 SQL 来获取一些索引:

select follow 
from unigram 
where alternativeSpelling like 'test' 
order by freq desc 
limit 10;

然后,我使用此 SQL 将它们一一转换为单词:

select word 
from wordIdxTranslate 
where word_idx = <one of the indexes from above>

如何将这些组合到一个查询中,同时保留第一个查询(“freq”)的排名顺序?

4

2 回答 2

3

未经测试,但应该这样做:

SELECT word 
FROM unigram, wordIdxTranslate
WHERE 
    unigram.follow=wordIdxTranslate.word_idx
    AND
    unigram.follow IN (SELECT T1.follow 
                       FROM unigram AS T1 
                       WHERE T1.alternativeSpelling LIKE 'test' 
                       ORDER BY T1.freq DESC 
                       LIMIT 10)
ORDER BY freq DESC
于 2012-06-10T16:32:28.703 回答
1

一种选择是将查询与 a 结合起来join,例如:

select  word 
from    (
        select  follow 
        ,       freq
        from    unigram 
        where   alternativeSpelling like 'test' 
        order by 
                freq desc 
        limit 10
        ) uni
join    wordIdxTranslate  wit
on      wit.word_idx = uni.follow
order by
        uni.freq desc
于 2012-06-10T16:28:32.757 回答