我有一个名为Branch的表,其中我有4列州,城市,分支机构,地址
如何编写查询以查找所有唯一状态。 它应该是List的形式。 像List;
答案 0 :(得分:0)
您可以使用原始查询来执行此操作。
public List<String> findUniqueStates(DaoSession session){
String query = "SELECT state FROM (SELECT state, COUNT(state) as count from Branch GROUP BY state) WHERE count = 1";
List<String> states = new ArrayList<String>();
Cursor c = session.getDatabase().rawQuery(query, null);
if (c.moveToFirst()) {
do {
states.add(c.getString(0));
} while (c.moveToNext());
}
c.close();
return states;
}