1

我正在尝试从表的单个列中获取所有唯一值。我完全失败了,文档似乎没有深入到足够的深度,我从查看源代码中收集到的内容似乎应该有所帮助,但没有。

List<Question> questions = new Select().from(Question.class).where("ZCLASSLEVEL = ? ", classLevel).execute();

努力获取所有问题的所有列。

然而,

List<Question> questions = new Select(columns).from(Question.class).where("ZCLASSLEVEL = ? ", classLevel).execute();

不返回任何数据(questions.size() = 0),我试过了

String[] columns = { "ZHRSSECTION" };

Select.Column[] columns = { new Select.Column("ZHRSSECTION", "ZHRSSECTION")};

据推测,在 Select() 之后抛出.distinct().应该只返回唯一值,但我什至不能只得到我感兴趣的单列来返回。

我在这里想念什么?

谢谢!兰迪

4

2 回答 2

1

你应该使用groupBy()方法来使用distinct()方法。

例如:

List<Question> questions = new Select()
    .distinct()
    .from(Question.class)
    .groupBy("ZCLASSLEVEL")
    .execute();

上面的代码返回一个问题列表,每个 ZCLASSLEVEL 一个(可能是最后一行)。

然后你可以得到 ZCLASSLEVEL 的唯一

for(Question question: questions){
    int level = question.ZCLASSLEVEL;
    //do something with level.
}
于 2016-11-02T14:21:02.290 回答
0

回答这个问题有点晚了,但问题是因为 SQLiteUtils.rawQuery() 假设 Id 列总是在游标结果中。将您的列 String[] 设置为 {Id, ZHRSSECTION} 就可以了。

    List<FooRecord> list = new Select(new String[]{"Id,tagName"}).from(FooRecord.class).execute();
于 2015-03-13T18:23:06.413 回答