我想使用 dbFlow 选择最常用的名称。在 SQLite 中,它将是:
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`))
我试过了:
SQLite.select(Employee_Table.name)
.from(Employee.class)
.groupBy(Employee_Table.name)
.having(Method.count().eq(
SQLite.select(
Method.max("cn")).from(
SQLite.select(Employee_Table.name, Method.count().as("cn"))
.from(Employee.class)
.groupBy(Employee_Table.name)
)
)
)
但是 Method.max 不接受别名。或者我应该只运行一个原始查询?