postgresql7.1
select count(*) as in_use
where exists (select tt.ticket_id
from ttracker_options ts,
ttracker_tickets tt,
ttracker_categories tc
where ts.option_id = :option_id
and tt.category_id = tc.category_id
and tc.package_id = ts.package_id
and ((ts.function = 'severity' and ts.value = tt.severity) or
(ts.function = 'priority' and ts.value = tt.priority)))