0

我想在 sqlite 中连接两列并在 concat 列上执行搜索。这可能吗?

Cursor mCursor = db.rawQuery(
                "SELECT user_id,firstname,lastname, \"firstname\" || \"lastname\" AS val FROM "
                        + TABLE_DIRECTORY + " where val ='%" + text + "%'",
                null);

使用 sqlite 和 android

4

3 回答 3

2

试试这个

   Cursor mCursor = db.rawQuery(
        "SELECT user_id,firstname,lastname, \"firstname\" || \"lastname\" AS val FROM "
                + TABLE_DIRECTORY + " where \"firstname\" || \"lastname\" LIKE '%" + text + "%'",
        null);
于 2012-08-10T07:18:16.833 回答
1
cursor = db.rawQuery("SELECT _id, firstName, lastName, FROM TABLE_DIRECTORY WHERE firstName || ' ' || lastName LIKE ?", 
                    new String[]{"%" + val + "%"});
于 2012-08-10T07:17:55.877 回答
0

我没试过,但只要我记得,你的 SQL 中有一个错误:

Cursor mCursor = db.rawQuery(
        "SELECT user_id,firstname,lastname, \"firstname\" || \"lastname\" AS val FROM "
                + TABLE_DIRECTORY + " where val LIKE '%" + text + "%'",
        null);

使用通配符的文本比较使用LIKE, not=

于 2012-08-10T07:16:54.193 回答