0
return mDb.query(DATABASE_TABLE, new String[] {rfrom
}, null, null, null, null, null);

以下のクエリは、sqlite の rawquery タグを使用した正しいステートメントです。私が欲しいのは、既存のsqliteのクエリを使用して、次のクエリステートメントを上記のクエリに置き換えたいということです。とにかくそのために完全なものはありますか?

select distinct col from 
(
    SELECT classa col FROM school 
    union all 
    SELECT classb col FROM school
) a 
order by col
4

1 に答える 1

0

以下のように使用して試すことができますSQLiteQueryBuilder

public void testUnionQuery() {
    String expected;
    String[] innerProjection = new String[] {"name", "age", "location"};
    SQLiteQueryBuilder employeeQueryBuilder = new SQLiteQueryBuilder();
    SQLiteQueryBuilder peopleQueryBuilder = new SQLiteQueryBuilder();
    employeeQueryBuilder.setTables("employee");
    peopleQueryBuilder.setTables("people");
    String employeeSubQuery = employeeQueryBuilder.buildUnionSubQuery(
            "_id", innerProjection,
            null, 2, "employee",
            "age=25",
            null, null, null);
    String peopleSubQuery = peopleQueryBuilder.buildUnionSubQuery(
            "_id", innerProjection,
            null, 2, "people",
            "location=LA",
            null, null, null);
    expected = "SELECT name, age, location FROM employee WHERE (age=25)";
    assertEquals(expected, employeeSubQuery);
    expected = "SELECT name, age, location FROM people WHERE (location=LA)";
    assertEquals(expected, peopleSubQuery);
    SQLiteQueryBuilder unionQueryBuilder = new SQLiteQueryBuilder();
    unionQueryBuilder.setDistinct(true);
    String unionQuery = unionQueryBuilder.buildUnionQuery(
            new String[] { employeeSubQuery, peopleSubQuery }, null, null);
    expected = "SELECT name, age, location FROM employee WHERE (age=25) " +
            "UNION SELECT name, age, location FROM people WHERE (location=LA)";
    assertEquals(expected, unionQuery);
}

詳細については、リンクをご覧ください

于 2013-01-18T11:50:29.380 に答える