I am trying to separate a computed field (in an example that it is called CALC_TIPS) by the average value for this computed field specified by the specific value COMM_TYPE_ID. With this query, I can extract the AVG for each COMM_TYPE_ID.
SELECT AVG(CALC_TIPS), COMM_TYPE_ID
FROM (SELECT tips_amount/COMMUNICATIONS_ID AS CALC_TIPS, COMM_TYPE_ID
FROM consumer_action_log) AS cal
GROUP BY COMM_TYPE_ID;
How can I then return and divide each value in the CALC_TIPS field by the average value for its COMM_TYPE_ID? I am now at a loss. Thanks in advance!
Note. I work with MySQL. Also Note: I know that a subquery is not needed. I use this request as a proxy for a more complex request, with which I have to do the same.
source
share