--Mode education for each occupation group SELECT freqeducation.worktype, freqeducation.educationlevel, freqeducation.cnt FROM (SELECT worktype, educationlevel, COUNT(*) as cnt FROM person GROUP BY worktype, educationlevel ) freqeducation JOIN (SELECT worktype, MAX(cnt) as maxcnt FROM (SELECT worktype, educationlevel, COUNT(*) as cnt FROM person GROUP BY worktype, educationlevel) c GROUP BY worktype ) educationmax ON freqeducation.worktype = educationmax.worktype AND freqeducation.cnt = educationmax.maxcnt ORDER BY 1, 2;