I have a table with Client IDs and amount spent. I can get a unique count of the clients and I can get a total spent. How do I get the average spent over all?
So I need to do my Total divided by Clients to get the average but not sure how to do that in MySQL. Been trying everything.
Yes, I know there is Average there but that will only get me the average of a column. For example it would get me an average of costs per transaction. but I need to know the averages based on the number of distinct clients.
SELECT
COUNT(DISTINCT cost_clientid) AS Clients,
SUM(cost_amount) AS Total,
(SUM(cost_amount) / COUNT(DISTINCT cost_clientid)) as Average
FROM
p_skillshighway_costs