Skip to content

Commit

Permalink
distinct
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Sikina committed Jul 21, 2024
1 parent b24ce80 commit f5924ab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
12 changes: 8 additions & 4 deletions one_facet.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{"facets":[
{"name":"LOINC","display":"LOINC","description":null,"count":1,"children":null,"category":"nsrr_harmonized","meta":null,"categoryRef":{"display":"Common Data Element Collection","name":"nsrr_harmonized","description":""}},
{"name":"PhenX","display":"PhenX","description":null,"count":1,"children":null,"category":"nsrr_harmonized","meta":null,"categoryRef":{"display":"Common Data Element Collection","name":"nsrr_harmonized","description":""}}],"search":""}

(
SELECT
facet.facet_id, count(*) as facet_count
Expand All @@ -10,7 +14,7 @@
LEFT JOIN concept_node_meta AS continuous_max ON concept_node.concept_node_id = continuous_max.concept_node_id AND continuous_max.KEY = 'max'
LEFT JOIN concept_node_meta AS categorical_values ON concept_node.concept_node_id = categorical_values.concept_node_id AND categorical_values.KEY = 'values'
WHERE
fc.name = 'study_ids_dataset_ids'
fc.name = 'nsrr_harmonized'
AND (
continuous_min.value <> '' OR
continuous_max.value <> '' OR
Expand All @@ -35,8 +39,8 @@ UNION
LEFT JOIN concept_node_meta AS continuous_max ON concept_node.concept_node_id = continuous_max.concept_node_id AND continuous_max.KEY = 'max'
LEFT JOIN concept_node_meta AS categorical_values ON concept_node.concept_node_id = categorical_values.concept_node_id AND categorical_values.KEY = 'values'
WHERE
fc.name = 'study_ids_dataset_ids'
AND facet.name IN ('phs000007')
fc.name = 'nsrr_harmonized'
AND facet.name IN ('LOINC', 'PhenX')
AND (
continuous_min.value <> '' OR
continuous_max.value <> '' OR
Expand All @@ -51,7 +55,7 @@ UNION
JOIN facet_category fc on fc.facet_category_id = facet.facet_category_id
JOIN matching_concepts ON fcn.concept_node_id = matching_concepts.concept_node_id
WHERE
fc.name <> 'study_ids_dataset_ids'
fc.name <> 'nsrr_harmonized'
GROUP BY
facet.facet_id
ORDER BY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private String createMultiCategorySQLWithSearch(Map<String, List<Facet>> facets,
return """
facet_category_%s_concepts AS (
SELECT
concept_node.concept_node_id
DISTINCT(concept_node.concept_node_id)
FROM
facet
JOIN facet__concept_node fcn ON fcn.facet_id = facet.facet_id
Expand Down Expand Up @@ -163,7 +163,7 @@ private String createMultiCategorySQLNoSearch(Map<String, List<Facet>> facets, M
return """
facet_category_%s_concepts AS (
SELECT
concept_node.concept_node_id
DISTINCT(concept_node.concept_node_id)
FROM
facet
JOIN facet__concept_node fcn ON fcn.facet_id = facet.facet_id
Expand Down Expand Up @@ -283,7 +283,7 @@ facet.facet_id, count(*) as facet_count
(
WITH matching_concepts AS (
SELECT
concept_node.concept_node_id AS concept_node_id
DISTINCT(concept_node.concept_node_id AS concept_node_id)
FROM
facet
JOIN facet_category fc on fc.facet_category_id = facet.facet_category_id
Expand Down Expand Up @@ -352,7 +352,7 @@ facet.facet_id, count(*) as facet_count
(
WITH matching_concepts AS (
SELECT
concept_node.concept_node_id AS concept_node_id
DISTINCT(concept_node.concept_node_id AS concept_node_id)
FROM
facet
JOIN facet__concept_node fcn ON fcn.facet_id = facet.facet_id
Expand Down

0 comments on commit f5924ab

Please sign in to comment.