我需要一个 SQL 查询来找到你可以用一组字母组成的所有单词,包括最多两个空白块

I need an SQL query to find all the words you can make with a set of letters, including up to two blank tiles

我有一个名为 dictionary 的数据库 table 当前所有字典条目都包含以下字段:

public static final String COLUMN_NAME_UID = "_id_";
public static final String COLUMN_NAME_WORD = "word";
public static final String COLUMN_NAME_WORD = "wordSorted";
public static final String COLUMN_NAME_WORD_LENGTH = "length";
public static final String COLUMN_NAME_COUNT_A = "count_A";
public static final String COLUMN_NAME_COUNT_B = "count_B";
public static final String COLUMN_NAME_COUNT_C = "count_C";
public static final String COLUMN_NAME_COUNT_D = "count_D";
public static final String COLUMN_NAME_COUNT_E = "count_E";
public static final String COLUMN_NAME_COUNT_F = "count_F";
public static final String COLUMN_NAME_COUNT_G = "count_G";
public static final String COLUMN_NAME_COUNT_H = "count_H";
public static final String COLUMN_NAME_COUNT_I = "count_I";
public static final String COLUMN_NAME_COUNT_J = "count_J";
public static final String COLUMN_NAME_COUNT_K = "count_K";
public static final String COLUMN_NAME_COUNT_L = "count_L";
public static final String COLUMN_NAME_COUNT_M = "count_M";
public static final String COLUMN_NAME_COUNT_N = "count_N";
public static final String COLUMN_NAME_COUNT_O = "count_O";
public static final String COLUMN_NAME_COUNT_P = "count_P";
public static final String COLUMN_NAME_COUNT_Q = "count_Q";
public static final String COLUMN_NAME_COUNT_R = "count_R";
public static final String COLUMN_NAME_COUNT_S = "count_S";
public static final String COLUMN_NAME_COUNT_T = "count_T";
public static final String COLUMN_NAME_COUNT_U = "count_U";
public static final String COLUMN_NAME_COUNT_V = "count_V";
public static final String COLUMN_NAME_COUNT_W = "count_W";
public static final String COLUMN_NAME_COUNT_X = "count_X";
public static final String COLUMN_NAME_COUNT_Y = "count_Y";
public static final String COLUMN_NAME_COUNT_Z = "count_Z";

我希望能够搜索实例 test* 并找到所有可以由 "t" "e" "s" "t" 和通配符组成的单词,比如"tests"(s是通配符),"setts"(s是通配符),"set","tet" "es" "te", "best"(b 是一个通配符),等等......你可以用这些字母的任意组合来做任何事情。

我试过这样的方法,但是这个例子只找到没有通配符的四个字母的单词:

SELECT * FROM dictionary WHERE 

count_E=1 AND
count_S=1 AND
count_T=2 

SELECT * FROM dictionary WHERE  length <=4

这会产生:

"137075"    "sett"  "estt"
"145808"    "stet"  "estt"
"153675"    "test"  "estt"
"153851"    "tets"  "estt"

现在,我知道,这在本质上是一个谨慎的数学问题。

这里是我如何得到一个空白的所有 5 个字母的单词 space 和最后一个查询中提供的所有字母:

SELECT * FROM dictionary WHERE 

count_E=1 AND
count_S=1 AND
count_T=2 

INTERSECT 
SELECT * FROM dictionary WHERE  length <=5

结果:

"97705"     "netts" "enstt"
"137075"    "sett"  "estt"
"145250"    "state" "aestt"
"145808"    "stet"  "estt"
"152303"    "taste" "aestt"
"152333"    "tates" "aestt"
"152632"    "teats" "aestt"
"153361"    "tents" "enstt"
"153675"    "test"  "estt"
"153676"    "testa" "aestt"
"153733"    "testy" "estty"
"153769"    "teths" "ehstt"
"153851"    "tets"  "estt"
"153874"    "texts" "esttx"
"156575"    "totes" "eostt"
"157952"    "trets" "erstt"
"172060"    "yetts" "estty"

但是,我必须遍历字母组合的所有迭代才能获得所有隐藏的子词...谁能帮我想出一种更优雅的方法来查找字谜和子词来自查询和最多两个通配符?我还知道您可以在 SQL 中使用 REGEXP,所以这可能是一种方式。我现在不知道,我正在把这个问题带到蜂巢...

是否有查询、查询系列、交集、连接等...可以帮助我解决这个问题?

更新 我想我可能偶然发现了这一点,但不确定它是否正常工作。任何帮助将不胜感激:

SELECT * FROM dictionary WHERE 
(
count_E<=1 AND
count_S<=1 AND
count_T<=1 
)
INTERSECT SELECT * FROM dictionary WHERE length =(count_E+count_S+count_T+1)     ORDER BY length

+1占一个空格space。对于两个,我正在考虑只做一个 +2,等等...... +0 就是那些字母,以及你可以从中得到的任何东西。

您必须执行以下操作,将 table 的所有字段串联起来,如下所示:

concatenacion = "(_id||' '||Desc_art||' '||Nom_proveedor||' '||marca) like '"+resultado+"'" +
            "OR (_id||' '||Nom_proveedor||' '||marca||' '||Desc_art) like '"+resultado+"'" +
            "OR (marca||' '||Nom_proveedor||' '||Desc_art||' '||_id) like '"+resultado+"'" +
            "OR (marca||' '||Nom_proveedor||' '||_id||' '||Desc_art) like '"+resultado+"'" +
            "OR (Desc_art||' '||Nom_proveedor||' '||marca||' '||_id) like '"+resultado+"'" +
            "OR (Desc_art||' '||_id||' '||Nom_proveedor||' '||marca) like '"+resultado+"'";

然后提出你的请求,在 WHERE 子句中必须把你的连接例如:

cursor=bd.rawQuery("select _id, Desc_art, cant_art, Desc_bulto, precio"+getDefaultNroLista(codcliente)+", tiene_imagen,marca from listas_precios where "+concatenacion+" ORDER BY Desc_art ASC", null);

我的工作很好,希望有用