It is now getting tricky indeed. How dynamic has this all to become. Here is an idea:
You can introduce a CTE in the WITH that counts the number of similarities based on S:
Code: Select all
similarities(c) AS (
SELECT count(distinct S) AS c
FROM PUBLIC.TEST -- TODO: Here has to go your table name
),
Code: Select all
AND ( (SELECT c FROM similarities) <= Y.level+1 OR instr(Y.s_con, CONCAT('-', X.s, '-')) = 0 )
This is just without any testing, but you might get the idea. So when you query more than the number of similarity sets, you get duplicates in the similarities.
Have fun, and I still expect contributions to the red cross organization for picking my brains.....
Edit: Changed join condition |