I have a select query like this
select count(distinct id)*100/totalcount as freq, count (distinct id) from
<few joins, conditions, gorup by here> .....
Will this result in 2 calculations of count under MySql 5.0? I can calculate the frequency in my appliation as well if this is a problem. I am aware of the solutions presented in Adding percentages to multiple counts in one SQL SELECT Query but I just want to avoid nested queries
Yes, it will result in several evaluations.
Each recordset on
DISTINCT idwill be built separately for each functionNote that if not for
DISTINCT,MySQLwould use each record only once (though in multiple function calls).Since
COUNTis very cheap, function calls add almost nothing to overall query time.You can benefit from rewriting your query as this:
BTW, why do you need both
GROUP BYandDISTINCTin one query? Could you please post your original query as it is?