Kor03d

Untitled

Jun 24th, 2019
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. select *
  2. from
  3.     (
  4.         select
  5.             c.concept_code,
  6.             c.concept_name,
  7.             coalesce (c1.concept_code, c2.concept_code) as target_code,
  8.             coalesce (c1.concept_name, c2.concept_name) as target_name
  9.         from concept_stage c
  10.         join concept_relationship_stage r on
  11.             c.concept_class_id = 'Drug Product' and
  12.             r.relationship_id = 'Maps to' and
  13.             c.concept_code = r.concept_code_1
  14.         left join concept c1 on
  15.             c1.concept_code = r.concept_code_2 and
  16.             c1.vocabulary_id = r.vocabulary_id_2
  17.         left join concept_stage c2 on
  18.             c2.concept_code = r.concept_code_2 and
  19.             c2.vocabulary_id = r.vocabulary_id_2
  20.     ) new
  21. join
  22.     (
  23.         select
  24.             c.concept_code,
  25.             c.concept_name,
  26.             coalesce (c1.concept_code, c2.concept_code) as target_code,
  27.             coalesce (c1.concept_name, c2.concept_name) as target_name
  28.         from concept_stage_old c
  29.         join concept_relationship_stage_old r on
  30.             c.concept_class_id = 'Drug Product' and
  31.             r.relationship_id = 'Maps to' and
  32.             c.concept_code = r.concept_code_1
  33.         left join concept c1 on
  34.             c1.concept_code = r.concept_code_2 and
  35.             c1.vocabulary_id = r.vocabulary_id_2
  36.         left join concept_stage_old c2 on
  37.             c2.concept_code = r.concept_code_2 and
  38.             c2.vocabulary_id = r.vocabulary_id_2
  39.     ) old
  40. on
  41.     new.concept_code = old.concept_code and
  42.     new.target_name != old.target_name
Advertisement
Add Comment
Please, Sign In to add comment