3 回答
TA贡献1824条经验 获得超6个赞
如果我理解正确,您想要取消透视数据,然后进行一些计数:
SELECT which,
SUM(CASE WHEN val > 0.5 THEN 1 ELSE 0 END)
FROM (SELECT time_secs, session, 'metric_1' as which, metric_1 as val
FROM full_ts
UNION ALL
SELECT time_secs, session, 'metric_1_likelihood' as which, metric_1_likelihood as val
FROM full_ts
SELECT time_secs, session, 'metric_2' as which, metric_2 as val
FROM full_ts
UNION ALL
SELECT time_secs, session, 'metric_2_likelihood' as which, metric_2_likelihood as val
FROM full_ts
) m
GROUP BY which;
编辑:
您可以通过执行以下操作来取消透视:
select c.which,
(case when c.which = 'metric_1' then t.metric_1
when c.which = 'metric_1_likelihood' then t.metric_1_likelihood
. . .
end) as val
from full_ts t cross join
(select 'metric_1' as which union all
select 'metric_1_likelihood' union all
. . .
) c(which)
TA贡献1820条经验 获得超10个赞
您需要使用条件聚合,只计算metric大于的行0.5:
SELECT COUNT(CASE WHEN metric_0 > 0.5 THEN 1 END) AS metric_0,
COUNT(CASE WHEN metric_0_likelihood > 0.5 THEN 1 END) AS metric_0_likelihood,
COUNT(CASE WHEN metric_1 > 0.5 THEN 1 END) AS metric_1,
COUNT(CASE WHEN metric_1_likelihood > 0.5 THEN 1 END) AS metric_1_likelihood,
-- etc etc etc
FROM yourtable
添加回答
举报