的回答我的問題PostgreSQL的ARRAY_AGG順序幾乎是在這裏:PostgreSQL array_agg order的窗函數
除此之外,我想ARRAY_AGG在窗函數:
select distinct c.concept_name,
array_agg(c2.vocabulary_id||':'||c2.concept_name
order by c2.vocabulary_id, c2.concept_name)
over (partition by ca.min_levels_of_separation),
ca.min_levels_of_separation
from concept c
join concept_ancestor ca on c.concept_id = ca.descendant_concept_id
and max_levels_of_separation > 0
join concept c2 on ca.ancestor_concept_id = c2.concept_id
where
c.concept_code = '44054006'
order by min_levels_of_separation;
所以,也許這將在未來的某個工作版本,但我得到這個錯誤
ERROR: aggregate ORDER BY is not implemented for window functions
LINE 2: select distinct c.concept_name, array_agg(c2.vocabulary_id||...
^
我也許應該從一個子查詢中選擇喜歡的第一個答案的問題引述以上建議。我希望能得到像命令那樣簡單的東西(在這個問題的第二個答案中)。或者,也許我只是懶惰的查詢,應該做group by
,而不是select distinct
。
我曾嘗試把順序由窗口函數(over (partition by ca.min_levels_of_separation order by c2.vocabulary_id, c2.concept_name)
),但我得到這些那種方式重複行:
"Type 2 diabetes mellitus";"{"MedDRA:Diabetes mellitus"}";1
"Type 2 diabetes mellitus";"{"MedDRA:Diabetes mellitus","MedDRA:Diabetes mellitus (incl subtypes)"}";1
"Type 2 diabetes mellitus";"{"MedDRA:Diabetes mellitus","MedDRA:Diabetes mellitus (incl subtypes)","SNOMED:Diabetes mellitus"}";1
(順便說一句:http://www.ohdsi.org/如果你恰巧是好奇,我得到了醫學詞彙表)
快速瀏覽 – AlexM