I am afraid that you may not be able to fulfill the request on such a problem so effectively.
You can create a WHERE like:
(`1` IN ARRAY(1,2,3,4,5,6,7) AND `2` IN ARRAY(1,2,3,4,5,6,7) AND `3` IN ARRAY(1,2,3,4,5,6,7) AND `4` IN ARRAY(1,2,3,4,5,6,7) AND `5` IN ARRAY(1,2,3,4,5,6,7)) OR (`1` IN ARRAY(1,2,3,4,5,6,7) AND `2` IN ARRAY(1,2,3,4,5,6,7) AND `3` IN ARRAY(1,2,3,4,5,6,7) AND `4` IN ARRAY(1,2,3,4,5,6,7) AND `6` IN ARRAY(1,2,3,4,5,6,7))
But it will be a hell of a condition. Alternatively, you can try using a combination:
First check if column 1 contains information:
IF( `1` IN ARRAY(1,2,3,4,5,6,7), 1, 0)
Then we summarize all this data:
SELECT ( IF( `1` IN ARRAY(1,2,3,4,5,6,7), 1, 0) + IF( `2` IN ARRAY(1,2,3,4,5,6,7), 1, 0) + IF( `3` IN ARRAY(1,2,3,4,5,6,7), 1, 0) + IF( `4` IN ARRAY(1,2,3,4,5,6,7), 1, 0) + IF( `5` IN ARRAY(1,2,3,4,5,6,7), 1, 0) + IF( `6` IN ARRAY(1,2,3,4,5,6,7), 1, 0) + IF( `7` IN ARRAY(1,2,3,4,5,6,7), 1, 0) ) AS `matches_cnt` FROM t1 HAVING `matches_cnt` >= 5
This will be an iteration over all the lines, and the condition will be quite complex (thus the performance of the bed).
You can also try replacing the values ββwith a binary string, for example:
1,2,7 = 01000011
And then calculate the Hamming distance between the registered record and the database, but this will only reduce the complexity of the condition, but you will need to repeat all the records remain the same.
Implementation in mysql with:
Replace the first part with:
SELECT ( $MAX_NUMBER$ - BIT_COUNT( XOR( `binary_representation`, $DATA_FROM_USER$)) ) AS `matches_cnt`