我在oracle中有这样的查询,但是我想要一个对应的蜂巢SQL。可以有人指导我下面的蜂巢等效物吗
'['|| LISTAGG(t3.measure_title,';')WITHIN GROUP(ORDER BY t3.measure_title)|| ']'all_measure_desc。如何在Hive中重写。
我在Oracle中的查询是
SELECT
t1.member_id,
t2.first_name,
t2.date_of_birth_sk,
'[' || LISTAGG(t3.measure_title, ';') WITHIN GROUP (ORDER BY t3.measure_title) || ']' all_measure_desc
FROM qms_gic_lifecycle t1
INNER JOIN dim_member t2
on t1.member_id = t2.member_id
INNER JOIN dim_quality_measure t3
on t1.quality_measure_id = t3.quality_measure_id
GROUP BY
t1.member_id,
t2.first_name,
t2.date_of_birth_sk;
答案 0 :(得分:0)
您可以使用collect_list
或collect_set
,具体取决于应如何处理重复值。 collect_list
保留重复的值,而collect_set
保留重复的值。
输出将是值的数组。
SELECT
t1.member_id,
t2.first_name,
t2.date_of_birth_sk,
COLLECT_LIST(t3.measure_title) as all_measure_desc
FROM qms_gic_lifecycle t1
INNER JOIN dim_member t2
on t1.member_id = t2.member_id
INNER JOIN dim_quality_measure t3
on t1.quality_measure_id = t3.quality_measure_id
GROUP BY
t1.member_id,
t2.first_name,
t2.date_of_birth_sk;
答案 1 :(得分:0)
您可以使用collect_list或collect_set,具体取决于应如何处理重复值。 collect_list保留重复的值,而collect_set消除重复的值。
输出将是一个值数组。
您可以使用concat_ws(string SEP,array)函数将结果数组转换为字符串
concat_ws(',', COLLECT_LIST(t3.measure_title) ) as all_measure_desc