How not to bring repeated description in the parameter?

Asked

Viewed 23 times

0

I have a dataset built for use as a parameter. However, several codes refer to the same description, and I cannot make the descriptions not repeat when placing the description as a search parameter. Follow the query:

with apg_cd_situacao (apg_cd_situacao, apg_cd_situacao_descricao) as (values 
    ('AA','Análise'), 
    ('DN','Análise'),
    ('DR','Análise'), 
    ('DP','Análise'),
    ('AN','Análise'), 
    ('AL','Análise'),
    ('DU','Análise')
)
select apg_cd_situacao, apg_cd_situacao_descricao
from apg_cd_situacao
;

I have tried to join the codes (('AA','DN', 'DR',...), 'Analysis'), but it is not working

  • Try to make a GROUP BY apg_cd_situacao_descricao and in the select list use some appropriate aggregation function, according to your DBMS, for example. array_agg(apg_cd_situacao) or string_agg(apg_cd_situacao).

1 answer

0

Try adding distinct at the beginning of the query.

  • with apg_cd_situacao (apg_cd_situacao, apg_cd_situacao_descricao) as (values ('AA', 'Analysis'), ('DN', 'Analysis'), ('DR', 'Analysis'), ('DP', 'Analysis'), ('AN', 'Analysis'), ('AL', 'Analysis'), ('DU','analysis') select distinct apg_cd_situacao, apg_cd_situacao_descricao from apg_cd_situacao ;
  • I had tried without success

Browser other questions tagged

You are not signed in. Login or sign up in order to post.