
Создаю запросы мастер-деталь следующего вида(FIBPlus):
Код: Выделить всё
fdset_datas.Close;//мастер-таблица
fdset_datas.SQLs.SelectSQL.Clear;
fdset_datas.SQLs.SelectSQL.Add('select distinct(iD_otd),NAim_OTD from rsx_mat');
fdset_detal.SQLs.SelectSQL.Clear;//деталь-таблица
fdset_detal.SQLs.SelectSQL.Add('select distinct(rsx_mat.id) as f_2,naim_mat,ed_izm,rasxod.id_mat,');
fdset_detal.SQLs.SelectSQL.Add('(select rsx_mat.cena*count(visits.id) from visits where opl=1 and dat>='+d1+' and dat<='+d2+
'and kod_usl in (select id_usl from rsx_mat where rsx_mat.id_otd=:ID_otd and rsx_mat.id=rasxod.id_mat))');
fdset_detal.SQLs.SelectSQL.Add('from rsx_mat,rasxod where rsx_mat.id_otd=:ID_otd and rasxod.id_mat=rsx_mat.id');
fdset_datas.Open;

Подскажите пожалуйста может запрос коряво написан? Может без IN можно как-то написать, а то без этой конструкции, по-другому я те же данные получить не могу - наверное просто знаний не хватает...
