Compute percents from SUM() in the same SELECT sql query
问题 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)