GROUP_CONCAT within another GROUP_CONCAT

1

I have a query that gives me a column with the following results:

0,1,1,1,1
1,1
0,1,1,0,1,1
0,1,1

I need if the string contains only a few, return me to, if it has only 0,1,1 or strings of 0,1,1 return me b and otherwise return me c

The result should be:

c
a
b
b

The query works until I try to put the GROUP_CONCAT within the GROUP_CONCAT (DISTINCT)

SELECT
t1.id,
(
  SELECT
  CASE
  WHEN GROUP_CONCAT(DISTINCT t3.type) = '1' THEN 'a'
  WHEN GROUP_CONCAT(DISTINCT REPLACE(GROUP_CONCAT(t3.type), '0,1,1', '2')) = '2' THEN 'b'
  ELSE 'c'
  END
  FROM table2 t2
  LEFT JOIN table3 t3 ON (t3.id_test = t2.id_test)
  WHERE t2.another_id = t1.another_id
) as value1
FROM table1 t1

For the case of the third row, if I change the REPLACE (GROUP_CONCAT ()) for its result "2.2" the error does not appear, but with this set it returns the following:

[Err] 1111 - Invalid use of group function

Thank you very much

    
asked by Dani 04.07.2018 в 17:10
source

0 answers