我想在sqlite中连接两列并在concat列上执行搜索。这可能吗?
Cursor mCursor = db.rawQuery(
"SELECT user_id,firstname,lastname, \"firstname\" || \"lastname\" AS val FROM "
+ TABLE_DIRECTORY + " where val ='%" + text + "%'",
null);
使用sqlite和android
答案 0 :(得分:2)
试试这个
Cursor mCursor = db.rawQuery(
"SELECT user_id,firstname,lastname, \"firstname\" || \"lastname\" AS val FROM "
+ TABLE_DIRECTORY + " where \"firstname\" || \"lastname\" LIKE '%" + text + "%'",
null);
答案 1 :(得分:1)
cursor = db.rawQuery("SELECT _id, firstName, lastName, FROM TABLE_DIRECTORY WHERE firstName || ' ' || lastName LIKE ?",
new String[]{"%" + val + "%"});
答案 2 :(得分:0)
我没试过,但只要我记得你的SQL中有错误:
Cursor mCursor = db.rawQuery(
"SELECT user_id,firstname,lastname, \"firstname\" || \"lastname\" AS val FROM "
+ TABLE_DIRECTORY + " where val LIKE '%" + text + "%'",
null);
与通配符的文本比较使用LIKE
,而不是=