2
我正在努力寻找一种很好的方法来做listagg
中的DISTINCT
红移。listagg与红移DISTINCT
我想要做的是列出产品的组合,但每行应返回不同产品的列表。
例
所需的输出:
bulb, light
bulb, light, fan
代替:
bulb, bulb, light
bulb, bulb, light, fan
下面是我的SQL:
select
tit.listagg
from (
SELECT
username,
listagg(node_name, ',')
WITHIN GROUP (ORDER BY node_name asc)
FROM table
Where node_type not like '%bla bla%'
GROUP BY username
) as tit
group by listagg;
现在,您可以在'listagg'内使用'DISTINCT'作为可选的子句。更多细节在这里:https://docs.aws.amazon.com/redshift/latest/dg/r_LISTAGG.html –