You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
WITH statins AS (
SELECT descendant_concept_id AS concept_id
FROM cdm.concept_ancestor
WHERE ancestor_concept_id = 1539403
), diuretics AS (
SELECT descendant_concept_id AS concept_id
FROM cdm.concept_ancestor
WHERE ancestor_concept_id = 974166
)
SELECT COUNT(DISTINCT de1.person_id) AS num_users,
COUNT(DISTINCT de2.person_id) AS also_bp
FROM cdm.drug_exposure de1
JOIN statins s
ON de1.drug_concept_id = s.concept_id
JOIN cdm.drug_exposure de2
ON de1.person_id = de2.person_id
LEFT JOIN diuretics d
ON de2.drug_concept_id = d.concept_id
AND de2.drug_exposure_start_date < de1.drug_exposure_end_date
AND de2.drug_exposure_end_date > de1.drug_exposure_start_date;
This is my proposed fix.
WITH drug_exposure1 AS (
SELECT de.person_id,
de.drug_exposure_start_date,
de.drug_exposure_end_date
FROM cdm.drug_exposure de
INNER JOIN cdm.concept_ancestor ca
ON de.drug_concept_id = ca.descendant_concept_id
WHERE ancestor_concept_id = 1539403
),
drug_exposure2 AS (
SELECT de.person_id,
de.drug_exposure_start_date,
de.drug_exposure_end_date
FROM cdm.drug_exposure de
INNER JOIN cdm.concept_ancestor ca
ON de.drug_concept_id = ca.descendant_concept_id
WHERE ancestor_concept_id = 974166
)
SELECT COUNT(DISTINCT de1.person_id) AS num_drug1_users,
COUNT(DISTINCT de2.person_id) AS also_drug2_users
FROM drug_exposure1 de1
LEFT JOIN drug_exposure2 de2
ON de1.person_id = de2.person_id
AND de2.drug_exposure_start_date < de1.drug_exposure_end_date
AND de2.drug_exposure_end_date > de1.drug_exposure_start_date;
The text was updated successfully, but these errors were encountered:
I think that this query is incorrect.
WITH statins AS (
SELECT descendant_concept_id AS concept_id
FROM cdm.concept_ancestor
WHERE ancestor_concept_id = 1539403
), diuretics AS (
SELECT descendant_concept_id AS concept_id
FROM cdm.concept_ancestor
WHERE ancestor_concept_id = 974166
)
SELECT COUNT(DISTINCT de1.person_id) AS num_users,
COUNT(DISTINCT de2.person_id) AS also_bp
FROM cdm.drug_exposure de1
JOIN statins s
ON de1.drug_concept_id = s.concept_id
JOIN cdm.drug_exposure de2
ON de1.person_id = de2.person_id
LEFT JOIN diuretics d
ON de2.drug_concept_id = d.concept_id
AND de2.drug_exposure_start_date < de1.drug_exposure_end_date
AND de2.drug_exposure_end_date > de1.drug_exposure_start_date;
This is my proposed fix.
WITH drug_exposure1 AS (
SELECT de.person_id,
de.drug_exposure_start_date,
de.drug_exposure_end_date
FROM cdm.drug_exposure de
INNER JOIN cdm.concept_ancestor ca
ON de.drug_concept_id = ca.descendant_concept_id
WHERE ancestor_concept_id = 1539403
),
drug_exposure2 AS (
SELECT de.person_id,
de.drug_exposure_start_date,
de.drug_exposure_end_date
FROM cdm.drug_exposure de
INNER JOIN cdm.concept_ancestor ca
ON de.drug_concept_id = ca.descendant_concept_id
WHERE ancestor_concept_id = 974166
)
SELECT COUNT(DISTINCT de1.person_id) AS num_drug1_users,
COUNT(DISTINCT de2.person_id) AS also_drug2_users
FROM drug_exposure1 de1
LEFT JOIN drug_exposure2 de2
ON de1.person_id = de2.person_id
AND de2.drug_exposure_start_date < de1.drug_exposure_end_date
AND de2.drug_exposure_end_date > de1.drug_exposure_start_date;
The text was updated successfully, but these errors were encountered: