select obj_id,
round(avg(t_min),2)as t_min,
round(avg(t_avg),2)as t_avg,
round(avg(t_max),2)as t_max,
round(avg(j_min),2)as j_min,
round(avg(j_avg),2)as j_avg,
round(avg(j_max),2)as j_max,
round(avg(lose),0)as lose,
max(coll_date)as coll_date
from itm_fp_fping
where coll_date >= TO_DATE('starttime','yyyy-mm-dd hh24:mi:ss')
and coll_date <= TO_DATE('endtime','yyyy-mm-dd hh24:mi:ss')
group by obj_id
t_min到j_max这六个字段有时会有一个-1值
我想在进行计算的时候不把这个-1算进去,应该怎么修改这条SQL?
------解决思路----------------------
with a (v_id,v_sal)
as
(select 1,200 from dual union all
select 2,400 from dual union all
select 3,-1 from dual union all
select 4,100 from dual union all
select 5,-1 from dual union all
select 6,200 from dual
)
select avg(decode(v_sal,-1,0,v_sal)) avg_bl , --计算平均值时也算上 -1的列
avg(decode(v_sal,-1,null,v_sal)) avg_qc --计算平均值时不算上 -1的列
from a;
------解决思路----------------------
如果是 分组函数的结果做处理,你用 having 就可以了
大概如下:
group by xx, xxx
having avg(n) <> -1