Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Mysql AVG basket size of customer

Below code returns AVG basket size per customer, would like to make another AVG of result received from bellow query.

Is it possible to achive with single query, or i simply have to run another query were i will calculate AVG(previousresult) ?

SELECT
    AVG(total_captured)
FROM
    tblbodo_sales
GROUP BY
    client_id;

Bellow is result of above query

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

28.35
5.35
5.07
5.66
5.9

By AVG(previusresult) i mean the following:

28.35+5.35+5.07+5.66+5.9/5

>Solution :

Yes in same query it is possible. Can you try the below one?

SELECT AVG(previousresult) FROM (
    SELECT
        AVG(total_captured) as previousresult
    FROM
        tblbodo_sales
    GROUP BY
        client_id) 
AS final_avg;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading