У меня есть запрос ниже, где мне нужно сделать DISTINCT ON
столбец allow_id из результата объединения, как это возможно в PostgreSQL. Я читал, что Snowflake использует похожий тип PostgreSQL, но DISTINCT ON
не работает.
select distinct on (allowed_id), * from (
select listagg(distinct id) as allowed_id, count (people) as totalpeople ,max(score) as maxscore , min(score) as minscore, 'n' as type from tableA
where userid = 123
union
select listagg(distinct id) as allowed_id, count (people) as totalpeople, max(elscore) as maxscore , min(elscore) as minscore, 'o' as type from tableB
where userid = 123
union
select listagg(distinct id) as allowed_id, null, null , null , 'j' as type from tableC
where userid = 123
union
select listagg(distinct id) as allowed_id, null, null , null , 'a' as type from tableD
where userid = 123
)