CO05: Breakout of condition by gender, age

Returns the distribution of condition breakouts per gender and age.

 Parameter  Example  Mandatory  Notes
condition_concept_id 31967 Yes Condition concept ID for 'Nausea'

Sample query run:
The following is a sample run of the query. The input parameters are highlighted in blue
SELECT concept_name AS gender, 
   SELECT gender_concept_id, age, COUNT(*)
   AS gender_age_freq
   FROM (
      SELECT year_of_birth, month_of_birth, day_of_birth, gender_concept_id, condition_start_date,
          DATEDIFF(years, CONVERT(DateTime, year_of_birth||'-01-01'), condition_start_date) AS age
      FROM (SELECT person_id, condition_start_date 
            FROM   condition_occurrence 
            WHERE  condition_concept_id = 31967
            AND    person_id IS NOT NULL) AS from_cond
      LEFT JOIN (select person_id, gender_concept_id, year_of_birth, month_of_birth, day_of_birth from person) as from_person
      ON from_cond.person_id=from_person.person_id
     ) AS gender_count
    GROUP BY gender_concept_id, age
    ORDER BY gender_age_freq
   ) AS gender_id_age_count
LEFT JOIN (select concept_id, concept_name from vocabulary.concept) as concept_list
ON  gender_id_age_count.gender_concept_id=concept_list.concept_id
ORDER BY gender_age_freq DESC
Output field list:
 Field  Description
gender A person's gender
age A person's age in years
gender_age_freq The frequency of a condition breakout for person gender at a certain age.

Sample output record:
 Field  Description
gender Female
age 50
gender_age_freq 3136