我有一个名为dictionary的数据库表,目前包含所有字典条目的以下字段:public static final String COLUMN_NAME_UID = _id_;public static final String COLUMN_NAME_WORD = word;public static final String C...
我有一个名为dictionary的数据库表,目前包含所有字典条目的以下字段:
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个字母的单词,其中包含一个空格和上一个查询中提供的所有字母:
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,这可能是一种方式.我不知道在这一点上,我把这个问题带到了蜂巢……
是否有查询,或一系列查询,交叉点,联接等…这有助于我解决这个问题?
UPDATE
我想我可能偶然发现了这一点,但我不确定它是否正常工作.任何帮助,将不胜感激:
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是占一个空白区域.对于两个人,我正在考虑做一个2等等… 0就是那些字母,以及你可以用它们制作的任何东西.
解决方法:
您必须执行以下操作,将表的所有字段连接在一起,如下所示:
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子句中必须以你的conecatenacion为例:
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);
我为我工作得很好,希望它有用
本文标题为:java – 我需要一个SQL查询来查找您可以使用一组字母创建的所有单词,包括最多两个空白区块
基础教程推荐
- 详细SpringBoot生命周期接口的使用 2022-11-12
- Springboot自动配置与@Configuration配置类详解 2023-02-28
- Java实现经典游戏俄罗斯方块(升级版)的示例代码 2023-05-14
- 关于springboot中对sqlSessionFactoryBean的自定义 2023-08-07
- Java日期工具类操作字符串Date和LocalDate互转 2023-01-08
- java 线程池存在的意义 2023-01-08
- Java效率提升神器jOOR 2023-02-19
- 基于雪花算法实现增强版ID生成器详解 2023-06-17
- Springboot详细讲解RocketMQ实现顺序消息的发送与消费流程 2023-01-29
- ReentrantReadWriteLock 读写锁分析总结 2022-11-25