I have a table:
name | doc | filter
NAME1 | DOC1 | A1
NAME1 | DOC1 | B1
NAME1 | DOC1 | C1
NAME2 | DOC2 | A1
NAME2 | DOC2 | D1
NAME2 | DOC2 | C1
NAME3 | DOC3 | B1
NAME3 | DOC3 | A1
So I create a SELECT command:
SELECT name, doc, array_agg(filter) filter from table group by name, doc, this return:
name | doc | filter
NAME1 | DOC1 | {A1,B1,C1}
NAME2 | DOC2 | {A1,D1,C1}
NAME3 | DOC3 | {B1,A1}
I am trying to create a SELECT command in prior table with the code below:
sum(case when array_agg(filter)::char like '%C1%' then 1 else 0 end) as "TOTAL"
But I receive the error:
aggregate function calls cannot be nested
How to solve it? If I want to add one more filter like this:
sum(case
when array_agg(filter)::char like '%C1%' or array_agg(filter)::char like '%C2%'
then 1 else 0
end) as "TOTAL"`
How to do?
array_agg(filter)::char like '%C1%'does not make any sense to me (and if you want to cast an array you should cast it to::text). What are you trying to do there? Count the number of values that areC1in thefiltercolumn? Please edit your question (by clicking on the edit link below it) and add some sample data and the expected output based on that data as formatted text. See here for some tips on how to create nice looking text tables.count(*) filter (where "filter" = 'C1')as total?filteris an array of many values that I need to found