2012-06-10 25 views
0

我用這個SQL抓住一些指標:聯袂翻譯表,保持訂單指數SQLite中

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」)的排序順序?

回答

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 
+0

Downvote不是從我這裏。答案似乎像廣告一樣工作,所以我很高興作爲一個蛤。 –

1

一種選擇是將查詢與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