amount of diagnosis for <5 >5 and amount of male and female mysql query -


i have 2 tables, 1 holding customer info , diagnosis done customers. want amount of diagnosis done <5 >5 , amount of male/female got diagnosis.

tables:

customers **name**       **pid**      **birth_date**    **sex** chris             1            1980-07-01        m jane              2            1977-10-05        f anna              3            1990-5-10         f david             4            2008-1-10         m naomi             5            2009-10-20        f juma              6            2010-10-15        m  **diagnosis** **pid**      **date_done**       **diagnosis_code**   1           2013-03-20           084   1           2013-03-13           019   2           2013-03-17           084   5           2013-03-13           037   3           2013-03-21           019   4           2013-03-01           037 

i want amount of diagnosis done <5 >5 , amount of diagnosis male , female month of march

                      year         gender      **diagnosis_code      <5   >5       male    female** ?                    ?     ?         ?        ? 

thanks in advance

you can group case should work.

select case when d.diagnosis_code <5 '<5' else '>5' end,        c.sex,        count(*) customers c join diagnosis d   on c.pid=d.pid d.diagnosis_code<>5   , month(d.date_done)=3 group case when d.diagnosis_code <5 '<5' else '>5' end,          c.sex; 

sqlfiddle (note 2 rows added diagnosis table).


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -