postgresql7.1
select u.user_id,
u.email,
u.last_name || ', ' || u.first_names as user_name,
d.download_date,
d.download_ip,
coalesce(d.download_hostname,'unavailable') as download_hostname,
coalesce(dar.version_name, 'unnamed') as version_name,
dar.revision_id,
case when d.reason_id is null then d.reason else dr.reason end as reason
from download_downloads d left join download_reasons dr
on (d.reason_id=dr.download_reason_id),
download_arch_revisions_obj dar,
cc_users u
where d.user_id = u.user_id
and dar.archive_id = :archive_id
and dar.revision_id = d.revision_id
[ad_dimensional_sql $dimensional where]
[ad_order_by_from_sort_spec $orderby $table_def]
dar.revision_id = content_item__get_live_revision(dar.archive_id)
d.download_date + '1 days'::interval > current_timestamp
d.download_date + '7 days'::interval > current_timestamp
d.download_date + '30 days'::interval > current_timestamp