select c.contragent_id c.contragent c.descr c.external_uid c.external_code c.is_provider (select count(*) from contract d where d.contragent_id=c.contragent_id) as contract_cnt (select count(*) from specification s join contract d on (s.contract_id=d.contract_id) where d.contragent_id=c.contragent_id) as spec_cnt from contragent c where 1=1 order by select count(*) as cnt from contragent where 1=1 Контрагенты title="редактировать" class="edit"title="просмотр" class="view"> #gridFooter#