postgresql7.1 select d.download_ip, coalesce(min(d.download_hostname),'unavailable') as download_hostname, count(*) as num_downloads from download_downloads_repository d, cc_users u where d.repository_id = :repository_id and d.user_id = u.user_id [ad_dimensional_sql $dimensional where] group by d.download_ip order by 2 d.download_date + '1 days'::interval > current_timestamp d.download_date + '7 days'::interval > current_timestamp d.download_date + '30 days'::interval > current_timestamp