ランキング アルゴリズムを使用して検索ルーチンを作成しており、これを 1 回のパスで取得したいと考えています。
私の理想的なクエリは次のようなものになります....
select *, (select top 1 wordposition
from wordpositions
where recordid=items.pk_itemid and wordid=79588 and nextwordid=64502
) as WordPos,
case when WordPos<11 then 1 else case WordPos<50 then 2 else case WordPos<100 then 3 else 4 end end end end as rank
from items
そのケースで WordPos を使用することは可能ですか? 無効な列名 'WordPos' というエラーが発生します。
ケースごとにサブクエリをやり直すことができることは知っていますが、実際にはケースを再実行すると思いますよね?
例えば:
select *, case when (select top 1 wordposition from wordpositions where recordid=items.pk_itemid and wordid=79588 and nextwordid=64502)<11 then 1 else case (select top 1 wordposition from wordpositions where recordid=items.pk_itemid and wordid=79588 and nextwordid=64502)<50 then 2 else case (select top 1 wordposition from wordpositions where recordid=items.pk_itemid and wordid=79588 and nextwordid=64502)<100 then 3 else 4 end end end end as rank from items
それは機能します....しかし、本当に毎回同じクエリを再実行していますか?
最初に実行するときは遅いが、その後の実行は速いため、テストから判断するのは難しい....キャッシングです...つまり、最初の行で初めて実行したとき、その後の3回キャッシュから結果を取得しますか?
これを行うための最良の方法が何であるかに興味があります...ありがとう!ライアン