postgresql7.1
select to_char(current_timestamp,'HH24')
+ (24 - (:end_time ::integer - $current_hour ::integer)) / 24
and (timestamp + :n_days ::integer $hour_correction) > current_timestamp
select pid, command, username,
count(*) as count,
$hour_sql as timestamp,
round(avg(threads)) as threads,
round(avg(to_number(rtrim(cpu_pct, '%'), '9999D99')), 2) as cpu_pct
from ( select * from ad_monitoring_top $time_clause ) t,
( select * from ad_monitoring_top_proc
where to_number(rtrim(cpu_pct, '%'), '9999D99') > :min_cpu_pct ) p
where p.top_id = t.top_id
group by pid, command, username, $hour_sql
[ad_order_by_from_sort_spec $orderby $top_proc_avg_table_def]
round(coalesce(avg(load_avg_1), 0), 2) as load_average,
round(coalesce(avg(memory_free),0), -2) as memory_free_average,
round(coalesce(avg(memory_swap_free), 0), -2) as memory_swap_free_average,
round(coalesce(avg(memory_swap_in_use),0), -2) as memory_swap_in_use_average
select max(timestamp) - min(timestamp) + '12 hours'::interval
from ad_monitoring_top $time_clause