1

4つのエントリを持つテーブルがあります。

    CREATE TABLE tab( 
    name Text 
                    ); 

    INSERT INTO "tab" VALUES('Intertek');
    INSERT INTO "tab" VALUES('Pntertek');
    INSERT INTO "tab" VALUES('Ontertek');
    INSERT INTO "tab" VALUES('ZTPay');

Pntertek と Ontertek は、正しい綴りの Intertek のあいまいな複製です。あいまいな重複と正しいスペルの名前で構成されるリストを作成したいと考えています。

私には 4 つの名前があるので、検索条件は 4 つあります。

    SELECT name FROM tab WHERE name LIKE '%ntertek' 
    AND (SELECT COUNT(*) FROM tab WHERE name LIKE '%ntertek') >1;
    SELECT name FROM tab WHERE name LIKE '%ntertek' 
    AND (SELECT COUNT(*) FROM tab WHERE name LIKE '%ntertek') >1;
    SELECT name FROM tab WHERE name LIKE '%ntertek' 
    AND (SELECT COUNT(*) FROM tab WHERE name LIKE '%ntertek') >1;
    SELECT name FROM tab WHERE name LIKE '%TPay' 
    AND (SELECT COUNT(*) FROM tab WHERE name LIKE '%TPay') >1;

これにより、同じ情報を含む 3 つのリストが作成されます。最初の SELECT ステートメントが結果を返す場合、2 番目と 3 番目の同一の SELECT ステートメントを無視したいと思います。これは SQLite を使用して可能ですか?どうすればよいですか?

私はSQLiteとプログラミング全般に関して非常に初心者なので、どんな助けでも大歓迎です。

前もって感謝します。

4

1 に答える 1

0

What do you want the query to return? Just potential duplicates? If so you could do the above with one query by including a having statement. However, the method that you are using at the moment only allows for differences at the start of the name. I would suggest looking into something like an edit-distance algorithm (sometimes referred to as Levenshtein distance) to identify the number of characters you would need to change on one field to make it the same as another.

There are details of a possible SQLite implementation in the following link: http://www.sqlite.org/spellfix1.html

于 2013-07-09T13:11:16.233 に答える