How can I get the percentage of total rows with mysql for a group?

后端 未结 2 1363
星月不相逢
星月不相逢 2021-01-20 20:41

below I have a query that will get the most common user agents for a site from a table of user agents and a linked table of ip addresses:

SELECT count(*) as          


        
2条回答
  •  星月不相逢
    2021-01-20 20:55

    If you add with rollup after your group by clause, then you will get a row where string is NULL and num is the total of all the browsers. You can then use that number to generate percentages.

    I can't really imagine a single query doing the calculation and being more efficient than using with rollup.

提交回复
热议问题