postgresql7.1 select to_char(current_timestamp,'HH24') + (24 - (:end_time ::integer - $current_hour ::integer)) / 24 select pid, command, username, $proc_time_sql, count(*) as count, round(avg(threads),0) as threads, round(avg(to_number(rtrim(cpu_pct, '%'), '9999D99')), 2) as cpu_pct from ( select * from ad_monitoring_top_proc where to_number(rtrim(cpu_pct, '%'), '9999D99') > :min_cpu_pct ) p, (select * from ad_monitoring_top $time_clause) t where p.top_id = t.top_id and $details_clause group by pid, command, username, $proc_group_by [ad_order_by_from_sort_spec $orderby $top_proc_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 count(*) 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 t.top_id = p.top_id and $details_clause