I am trying to know how frequently an event happens, and the occurence of this event in my database is recorded by setting a boolean to 'TRUE' and the non-occurence is setting it to 'FALSE'.
But when I am try to select the value by using the function avg() it returns me this error: ERROR: function avg(boolean) does not exist
How can I measure the event frequency and at the some time keep a good performance ?
Thank you.
Joao
This will coerce the value into 0's and 1's
select avg(val::int);
You could do this:
AVG(CASE WHEN myBooleanAttribute = TRUE THEN 1 ELSE 0 END)
If you cast as int you will get an int average, which isnt very useful. Instead try:
select avg(val::int::float4);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With