mysql - Sub query with count -
this query works fine , list of (male,female) items.
select dmg.dmg_sex demographic dmg join link lnk on lnk.lnk_dmgid = dmg.dmg_id join admission adm on adm.adm_id = lnk.lnk_admid adm.adm_id in (select distinct(adm.adm_id) admission adm join link lnk on lnk.lnk_admid = adm.adm_id join daily_link dlnk on dlnk.dlk_lnkid = lnk.lnk_id dlnk.dlk_assessdate >= '2011/01/01' , dlnk.dlk_assessdate <= '2011/03/31')
if male, female result in counted list
select dmg.dmg_sex, count (dmg.dmg_sex) demographic dmg join link lnk on lnk.lnk_dmgid = dmg.dmg_id join admission adm on adm.adm_id = lnk.lnk_admid adm.adm_referraldate >= '2011/01/01' , adm.adm_referraldate <= '2011/03/31' group dmg.dmg_sex desc
but trying combine 2 queries adding count (dmg.dmg_sex)
first query not work. why or missing something
select dmg.dmg_sex, count (dmg.dmg_sex) demographic dmg join link lnk on lnk.lnk_dmgid = dmg.dmg_id join admission adm on adm.adm_id = lnk.lnk_admid adm.adm_id in (select distinct(adm.adm_id) admission adm join link lnk on lnk.lnk_admid = adm.adm_id join daily_link dlnk on dlnk.dlk_lnkid = lnk.lnk_id dlnk.dlk_assessdate >= '2011/01/01' , dlnk.dlk_assessdate <= '2011/03/31')
desired output
male 243
female 183
output getting now
male
male
male
male
male
male
female
female
female
female
female
female
female
to able count sex need following sql combine sql
group dmg.dmg_sex desc
Comments
Post a Comment