This query is used to count the age across all observation records stratified by gender (gender_concept_id). The age value is defined by the earliest observation date. Age is summarized for all existing gender_concept_id values.
SELECT
age,
gender,
COUNT(*)::integer AS num_people
FROM
( SELECT
w.person_id,
coalesce( concept_name, 'MISSING' ) AS gender,
date_part('year', first_observation_date ) - year_of_birth AS age
FROM
( SELECT
person_id,
MIN( observation_period_start_date ) AS first_observation_date
FROM @cdm.observation_period
GROUP BY person_id
) AS w
INNER JOIN @cdm.person
ON w.person_id = person.person_id
LEFT OUTER JOIN @vocab.concept
ON person.gender_concept_id = concept.concept_id
WHERE date_part('year',first_observation_date) - year_of_birth >= 0
) AS z
GROUP BY age, gender
ORDER BY age, gender;
None
| Field | Description | | --- | --- | | age | Age across within observation | | gender | Gender concept name stratification | | num_people | Number of person within group |
| Field | Description | | --- | --- | | age | 1 | | gender | MALE | | num_people | 22501 |
https://github.com/OHDSI/CommonDataModel/wiki/
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.