samedi 20 février 2016

Duplicate field values in SQLite

I am using SQLite 3.11. I create a table as follows:

            CREATE TABLE MyTable (F1 INTEGER, F2 INTEGER, F3 INTEGER);

Then add the following records:

            INSERT INTO MyTable (F1, F2, F3) Values (1, 2, 8); 
            INSERT INTO MyTable (F1, F2, F3) Values (1, 3, 9);
            INSERT INTO MyTable (F1, F2, F3) Values (2, 4, 8);
            INSERT INTO MyTable (F1, F2, F3) Values (2, 5, 2);
            INSERT INTO MyTable (F1, F2, F3) Values (3, 6, 4);
            INSERT INTO MyTable (F1, F2, F3) Values (3, 7, 8);
            INSERT INTO MyTable (F1, F2, F3) Values (4, 2, 4);

Now if two records have the same value of F1, then I will define them as conflict records.

I want to select all the records whose (F3 & 8) != 0 where (F3 & 8) means to get the third bit of the F3 value. Moreover, for conflict records, I will order them by F2 and only the record with the largest F2 will be selected.

So for the above sample, the following record will be selected:

            (1, 3, 9)
            (2, 4, 8)
            (3, 7, 8)
            (4, 2, 4)

How to do that?

Thanks

Aucun commentaire:

Enregistrer un commentaire