How to calculate % of total in MySQL

PMa

I have the following qry:

select count(*) as headct
, case
when year(DOB) <= 1945 then 'Traditionalist'
when year(DOB) >= 1946 and year(DOB) < 1965 then 'Baby Boomer'
when year(DOB) >= 1965 and year(DOB) < 1981 then 'Gen X'
when year(DOB) >= 1981 then 'Gen Y'
end as generation
from ret_active
group by Generation with rollup;

It returns this table:

headct    generation
--------------------------
1820      Baby Boomer
2208      Gen X
883       Gen Y
17        Traditionalist
4928      null

How can I add another column where I can show the % of total for each category? In other words, how can I get the following results:

headct    generation      % of Total
-------------------------------------
1820      Baby Boomer     37%
2208      Gen Xm          45%
883       Gen Y           18%
17        Traditionalist  0%
4928      null            100%

Thanks!

Ron Smith
select count(*) as headct
, case
    when year(DOB) <= 1945 then 'Traditionalist'
    when year(DOB) >= 1946 and year(DOB) < 1965 then 'Baby Boomer'
    when year(DOB) >= 1965 and year(DOB) < 1981 then 'Gen X'
    when year(DOB) >= 1981 then 'Gen Y'
  end as generation
, concat(round(count(*)/
    (select count(*) from ret_active)*100,0),'%') as '% of Total'
from ret_active
group by Generation with rollup

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to calculate % of total in MySQL

From Dev

How to calculate total tickets available and total tickets sold using MySQL?

From Dev

How to calculate total time between datetime stamps in MySQL

From Dev

how to calculate total number of saturday and sunday between two dates in mysql

From Dev

Javascript: how to calculate the total

From Dev

How to calculate the total of a sum in JSTL

From Dev

How to calculate "running total" in SQL

From Dev

How to calculate total price in php

From Dev

how to calculate total Sum in Excel

From Dev

How to calculate the total distance traveled?

From Dev

How to Calculate Total Less Duplicates?

From Dev

How to calculate Last column total

From Dev

How to calculate a running total in view?

From Dev

How to calculate total price of order?

From Dev

How to Calculate Bill Total JS

From Dev

Mysql Calculate total memory based on prefix

From Dev

How can I calculate the total duration between two date/times with MySQL

From Dev

How do I calculate the sub total and total in a table in the PHP?

From Dev

How to split range of number and calculate total range?

From Dev

How to calculate total price of an order with Rails?

From Dev

How to calculate the running total using aggregate

From Dev

How to calculate Total with ng-repeat

From Dev

How to calculate the percentage of total in Spark SQL

From Dev

How to calculate the daily cost based on total hours?

From Dev

How to calculate total row heights of listView in android?

From Dev

How to Calculate Total Duration of Multiple Video Clips?

From Dev

How to calculate total of cells while there are blank ones?

From Dev

How to calculate total from select fields with Javascript?

From Dev

How to calculate with php the total with a VAT percentage in PHP

Related Related

  1. 1

    How to calculate % of total in MySQL

  2. 2

    How to calculate total tickets available and total tickets sold using MySQL?

  3. 3

    How to calculate total time between datetime stamps in MySQL

  4. 4

    how to calculate total number of saturday and sunday between two dates in mysql

  5. 5

    Javascript: how to calculate the total

  6. 6

    How to calculate the total of a sum in JSTL

  7. 7

    How to calculate "running total" in SQL

  8. 8

    How to calculate total price in php

  9. 9

    how to calculate total Sum in Excel

  10. 10

    How to calculate the total distance traveled?

  11. 11

    How to Calculate Total Less Duplicates?

  12. 12

    How to calculate Last column total

  13. 13

    How to calculate a running total in view?

  14. 14

    How to calculate total price of order?

  15. 15

    How to Calculate Bill Total JS

  16. 16

    Mysql Calculate total memory based on prefix

  17. 17

    How can I calculate the total duration between two date/times with MySQL

  18. 18

    How do I calculate the sub total and total in a table in the PHP?

  19. 19

    How to split range of number and calculate total range?

  20. 20

    How to calculate total price of an order with Rails?

  21. 21

    How to calculate the running total using aggregate

  22. 22

    How to calculate Total with ng-repeat

  23. 23

    How to calculate the percentage of total in Spark SQL

  24. 24

    How to calculate the daily cost based on total hours?

  25. 25

    How to calculate total row heights of listView in android?

  26. 26

    How to Calculate Total Duration of Multiple Video Clips?

  27. 27

    How to calculate total of cells while there are blank ones?

  28. 28

    How to calculate total from select fields with Javascript?

  29. 29

    How to calculate with php the total with a VAT percentage in PHP

HotTag

Archive