I have a table of Padlocks which (unfortunately) consists of a column with comma-separated data. Table consists of padlocks with information of types of Locks given padlock has (and whether it s big or small). Given a key, which can unlock certain types of locks (and size) I want to find which Padlocks I would be able to unlock. A key has also a comma-separated Lock types and a size.
<>12>
Name | Locks | Size |
---|---|---|
A | KL, OK, CZ, CZ | Small |
B | OK, OK | Small |
C | OK, CZ, KL | Small |
D | RO, CZ, CZ | Small |
E | OK, OK, KL, KL | Small |
F | OK, OK, CZ, KL | Big |
(Input) Key (KL, OK, OK, OK, CZ, CZ , Small ) will 回去
Name |
---|
A |
B |
C |
请注意,如果钥匙能够只打开一例KL,那么它不会锁定Padlock E,因为它需要双倍的KL, KL 。 Padlock D 不能因为需要RO而锁定。 Padlock 不能因为需要大钥匙而孤立。
如果是一些方案语言,如C#,I d分裂了对阵列[KL 、OK 、OK 、 CZ 、 CZ]的关键投入,而且对于每个行,我也将把洛克数分成阵列,对两个阵列进行比较。
Pseudocode
foreach Lock in Locks
for(i=0;i<UBound(Lock);i++)
for(j=0;i<UBound(Key);j++)
If(Lock[i]=Key[j]) Lock[i].Remove Key[j].Remove
If at some point Lock is left with 0 values then the Key can open that lock. But that is way over what I can do in MariaDB. I know of FIND_IN_SET() but that would let me search for one input only, unless there is a way to use it to fit my needs
PS Select @@version = 10.3.39-MariaDB-0+deb10u2
PS2 Would normalizing help? I mean, I could create a table Locks which would hold all the lock types and then create a cross reference table for Padlocks<->Locks. Would there be an SQL statement that would let me get what I need?