我正在研究红移查询,该查询将获取比率并将其与阈值进行比较。如果阈值较高,则将1作为标志。
我相信具有比例的case语句由于某些十进制数字未对齐而导致此错误。
以下是查询:
select
datepart(week, date_trunc('week',d.reporting_date+1)-1 )as reporting_week,
date_trunc('week',d.reporting_date+1)-1 as reporting_date,
nvl(sum(d.metric_num),0)as metric_num,
nvl(sum(d.metric_den),1) as metric_den,
nvl(sum(d.metric_num),0)/ nvl(sum(d.metric_den),1) as ratio,
case when sum(d.metric_num) > d.metric_target and metric_group in ('metric2') then 1
when nvl(round(ratio, 1),0 )> round(metric_target, 1) and d.metric_name in ('metric1') then 1
end as callout
from table1 d
group by 1,2,metric_name
having callout=1
order by date_trunc('week',d.reporting_date+1)-1 desc