In the table my_obj
there are two integer fields:
(value_a integer, value_b integer);
I try to compute how many time value_a = value_b
, and I want to express this ratio in percents.
This is the code I have tried:
select sum(case when o.value_a = o.value_b then 1 else 0 end) as nb_ok,
sum(case when o.value_a != o.value_b then 1 else 0 end) as nb_not_ok,
compute_percent(nb_ok,nb_not_ok)
from my_obj as o
group by o.property_name;
compute_percent
is a stored_procedure that simply does (a * 100) / (a + b)
But PostgreSQL complains that the column nb_ok
doesn't exist.
How would you do that properly ?
I use PostgreSQL 9.1 with Ubuntu 12.04.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…