postgresql7.1
select wta.party_id,
acs_object__name(wta.party_id) as party_name,
count(ticket_id) as total,
sum(case when lower(wc.state)='active' then 1 else 0 end) as active,
sum(case when lower(wc.state)='suspended' then 1 else 0 end) as suspended,
sum(case when lower(wc.state)='canceled' then 1 else 0 end) as canceled,
sum(case when lower(wc.state)='finished' then 1 else 0 end) as finished,
max(tt.creation_date) as latest,
min(tt.creation_date) as oldest
from ttracker_tickets tt,
ttracker_categories tc,
wf_cases wc,
wf_task_assignments wta
where tc.package_id = :package_id and
tt.category_id = tc.category_id and
tt.ticket_id = wc.object_id and
wta.task_id = (select max(wt.task_id)
from wf_tasks wt
where wt.case_id = wc.case_id and
wt.transition_key = 'resolve')
[ad_dimensional_sql $dimensional]
group by wta.party_id
[ad_order_by_from_sort_spec $orderby $table_def]
tt.creation_date + '365 days'::interval > now()
tt.creation_date + '90 days'::interval > now()
tt.creation_date + '30 days'::interval > now()