Здравствуйте, Сергей!
Sergey Mereutsa wrote:
Подсчет количества найденных документов (ну вот захотелось им
такую фичу и все):
select count(d.id) from t_documents d,
(select w.document_id, count(1) as cnt from t_search_words w,
( select 2624961196 as wrd from rdb$database union
select 1902388292 as wrd from rdb$database union
select 1228066714 as wrd from rdb$database ) t1
where w.lang_id=2 and w.flag=1 and w.word=t1.wrd
group by 1 order by 2 desc ) idx
where d.lang_id=2 and d.published_when>='01.07.2002' and
d.published_when<='02.07.2007' and d.publisher_id =36149 and
d.id=idx.document_id and idx.cnt=3
Извините, что влезаю, но никак не могу понять, зачем order by 2 desc в idx?
Правильно ли я понимаю, что Ваш запрос эквивалентен следующему:
select count(1) from t_documents d,
(select w.document_id from t_search_words w,
( select 2624961196 as wrd from rdb$database union
select 1902388292 as wrd from rdb$database union
select 1228066714 as wrd from rdb$database ) t1
where w.lang_id=2 and w.flag=1 and w.word=t1.wrd
group by 1
Having Count(1) = 3 ) idx
where d.lang_id = 2
and d.published_when >= '01.07.2002'
and d.published_when <= '02.07.2007'
and d.publisher_id = 36149
and d.id = idx.document_id ?
или, если взять за основу вариант Влада Хорсуна,
select count(1) from t_documents d,
(select w.document_id from t_search_words w cross join rdb$database
where w.lang_id=2 and w.flag=1
and w.word in (2624961196, 1902388292, 1228066714)
group by 1
having Count(1) = 3) idx
where d.lang_id=2
and d.published_when>='01.07.2002'
and d.published_when<='02.07.2007'
and d.publisher_id =36149
and d.id=idx.document_id ?
С уважением, Евгений.