Open sanikolaev opened 2 years ago
If it just want sum(if(a,1,0))/count(*)
specifically, can use avg(if(a,1,0))
- if think about what avg()
does internally it's the same thing. Useful trick if wanting order results by a 'percentage'.
select sum(if(a=1,1,0)),count(*),avg(if(a=1,1,0)) from t;
+------------------+----------+------------------+
| sum(if(a=1,1,0)) | count(*) | avg(if(a=1,1,0)) |
+------------------+----------+------------------+
| 2 | 3 | 0.66666667 |
+------------------+----------+------------------+
1 row in set (0.001 sec)
But yes, agree it would be nice to be able to more general expressions with aggregates.
Things like
select sum(...) / count(*)
etc. are not allowed now:The workaround is to decompose the expression:
and calculate the result outside Manticore.
The suggestion is to make it possible to do the calculations right in Manticore.