Calculate percentage and total after create categories mysql -


i've query

select      trage,     case trage          when '<18' sum(case when age <18 1 else 0 end)         when '18-24' sum(case when age >= 18 , age <= 24 1 else 0 end)         when '25-34' sum(case when age >= 25 , age <= 34 1 else 0 end)         when '35-44' sum(case when age >= 35 , age <= 44 1 else 0 end)         when '45-54' sum(case when age >= 45 , age <= 54 1 else 0 end)         when '>=55' sum(case when age >= 55 1 else 0 end)     end total  (   select          t_personne.pers_date_naissance,          t_personne.pers_date_inscription,          timestampdiff(year, t_personne.pers_date_naissance, t_personne.pers_date_inscription)          - case              when month(t_personne.pers_date_naissance) > month(t_personne.pers_date_inscription)               or (month(t_personne.pers_date_naissance) = month(t_personne.pers_date_inscription)               , day(t_personne.pers_date_naissance) > day(t_personne.pers_date_inscription))             1 else 0            end age     t_personne ) total cross join (   select '<18' trage union     select '18-24' union     select '25-34' union     select '35-44' union     select '45-54' union     select '>=55' )a group trage order field(trage, '<18', '18-24', '25-34', '35-44', '45-54', '>=55') 

it give table 2 columns trage , total categories

how add column percentage line total column total , %

thanks help

for time being, can't this. support mysql needs window function support still doesn't have. if need functions these recommend switching postgresql.

also take @ question: mysql using correct syntax on clause


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -