2

在我之前的应用程序中,我从 sqlite 数据库中的表中检索数据。所以我使用以下方式获取数据:

cursor = database.query("CIRCLE", new String[] { "CIRCLE_ID",
            "ZONE_ID", "NAME" }, "ZONE_ID = " + id, null, null, null, "NAME");
    cursor.moveToFirst();
    if (!cursor.isAfterLast()) {
        do {
            circleLists.add(new CircleList(cursor.getInt(0), cursor
                    .getInt(1), cursor.getString(2)));
        } while (cursor.moveToNext());
    }
    cursor.close();

现在我需要从一个表中检索数据,该表的 id 与其他表的 id 匹配,并且条件匹配来自其他表的 id(在获取数据后)。我有 SQL 查询。我不知道如何在cursor = database.query(...)中实现这个查询

SQL查询是:

select d.division_id, d.name from division d, division_circle_assoc dca
where d.division_id = dca.division_id and dca.circle_id = 1
4

1 回答 1

1
cursor = database.rawQuery("select d.division_id, d.name from division d, division_circle_assoc dca
where d.division_id = dca.division_id and dca.circle_id = 1", null);

String[] columns = new String[] { KEY_D_ID, KEY_NAME};
             String whereClause = KEY_D_ID + "=" + KEY_DD_ID +" AND "+ KEY_C_ID +"= 1";
             Cursor cursor = mDb.query(true, DIVISION + " INNER JOIN "+ DIVISION_CIRCLE, columns, whereClause, null, null, null, null, null);
于 2013-06-12T05:12:12.923 回答