hi to all
I have a query that correctly produces the 720 permutations of the digits 0, 1, 2, 3, 4, 5.
Here's the SQL, followed by a sample of the output. tbl_K has one field, ID, with records 0, 1, 2, 3, 4, 5.
The output has 720 records like...
Here is my problem, and I'm really lost as to how to handle it:
I need to FILTER out most of these 720 records by applying the following constraints.
Reading an output record from LEFT to RIGHT...
[tt]a) 0 must precede 1, 2, 3, 4 and 5 (for eg, record 1, 0, 3, 4, 2, 5 is NOT allowed)
b) 2 must precede 3, 4 and 5 (for eg, record 0, 1, 4, 5, 2, 3 is NOT allowed)
c) 4 must precede 5 (for eg, record 0, 2, 1, 5, 4, 3 is NOT allowed)[/tt]
An example of a valid record is ( 0, 2, 1, 4, 3, 5 ) because it meets all 3 constraints.
Thanks in advance for any pointers
Vicky C.
I have a query that correctly produces the 720 permutations of the digits 0, 1, 2, 3, 4, 5.
Here's the SQL, followed by a sample of the output. tbl_K has one field, ID, with records 0, 1, 2, 3, 4, 5.
Code:
SELECT T_0.ID AS A, T_1.ID AS B, T_2.ID AS C, T_3.ID AS D, T_4.ID AS E, T_5.ID AS F
FROM tbl_K AS T_0, tbl_K AS T_1, tbl_K AS T_2, tbl_K AS T_3, tbl_K AS T_4, tbl_K AS T_5
WHERE ((T_0.ID<>T_1.ID) And (T_0.ID<>T_2.ID) And (T_0.ID<>T_3.ID) And (T_0.ID<>T_4.ID) And (T_0.ID<>T_5.ID))
And ((T_1.ID<>T_2.ID) And (T_1.ID<>T_3.ID) And (T_1.ID<>T_4.ID) And (T_1.ID<>T_5.ID))
And ((T_2.ID<>T_3.ID) And (T_2.ID<>T_4.ID) And (T_2.ID<>T_5.ID))
And ((T_3.ID<>T_4.ID) And (T_3.ID<>T_5.ID))
And ((T_4.ID<>T_5.ID));
The output has 720 records like...
Code:
A B C D E F
0 1 2 3 4 5
0 1 2 3 5 4
0 1 2 4 3 5
0 1 2 4 5 3
0 1 2 5 3 4
0 1 2 5 4 3
.... etc
5 4 3 1 2 0
5 4 3 2 0 1
5 4 3 2 1 0
Here is my problem, and I'm really lost as to how to handle it:
I need to FILTER out most of these 720 records by applying the following constraints.
Reading an output record from LEFT to RIGHT...
[tt]a) 0 must precede 1, 2, 3, 4 and 5 (for eg, record 1, 0, 3, 4, 2, 5 is NOT allowed)
b) 2 must precede 3, 4 and 5 (for eg, record 0, 1, 4, 5, 2, 3 is NOT allowed)
c) 4 must precede 5 (for eg, record 0, 2, 1, 5, 4, 3 is NOT allowed)[/tt]
An example of a valid record is ( 0, 2, 1, 4, 3, 5 ) because it meets all 3 constraints.
Thanks in advance for any pointers
Vicky C.