DBFlow Android选择最常见的值

时间:2017-08-15 10:45:11

标签: android sqlite dbflow

我想使用dbFlow选择最常用的名称。 在SQLite中它将是:

values = values & "'" & Nz(ID) & "','" & Nz(A) & "','" & Nz(B) & "','" & Nz(C) & "')"

我试过了:

SELECT `Employee`.name
FROM `Employee`
GROUP BY `Employee`.name
HAVING COUNT(*) =
  (SELECT MAX(cn) FROM
     (SELECT `Employee`.name, COUNT(*) AS cn
      FROM `Employee`
      GROUP BY `name`))

但Method.max不接受别名。或者我应该只运行一个原始查询?

1 个答案:

答案 0 :(得分:1)

Method.max只接受属性 您可以使用。

创建一个
+-----------+--------------------+---------------+--------------+---------------+
|   name    |   source_database  | source_schema | source_table | source_column |
+-----------+--------------------+---------------+--------------+---------------+
| PK_id     | fiddle_0f9d47226c4 | dbo           | txu          | id            |
| name      | fiddle_0f9d47226c4 | dbo           | txu          | first_name    |
| address   | fiddle_0f9d47226c4 | dbo           | txd          | address       |
| name_full | null               | null          | null         | null          |
+-----------+--------------------+---------------+--------------+---------------+

用法:

public static Property<Long> name(String value) {
    return new Property<Long>(null, value) {
        @Override
        public String toString() {
            return nameAlias.nameRaw();
        }
    };
}