Re: Selecting unique random combinations from a table
Posted: Fri Jun 04, 2021 10:04 am
@dream, not nice to change the rules during the game, but good that you have been able to implement the check on S.
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:
We can use this CTE 'similarities.c' in the join condition on S in the recursive query:
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.....
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 |