聚合函数未在GROUP BY子句中被Alloowed(代码1)

时间:2018-02-23 12:12:05

标签: android sqlite

我在Android 4.4.2版本的设备中遇到了以下奇怪的Sqlite查询问题。提前谢谢

表格结构如下

CREATE TABLE responsemaster (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    formid integer,
    proposerid text,
    fieldid integer,
    response text,
    remarks text,
    listId integer,
    isMarked integer
)

和提供错误的查询是

SELECT id as id, formid as formid, proposerid as proposerid, MIN(fieldid) fieldid, response as response, remarks as remarks, listId as listId, isMarked as isMarked
FROM responsemaster
WHERE formid = 40066 AND proposerid = '7ca6533a-c5f0-43e2-9980-83f9ae2c7370201802230113550000'
GROUP BY fieldid

我得到的例外情况如下

android.database.sqlite.SQLiteException: aggregate functions are not allowed in the GROUP BY clause (code 1):, 
while compiling: SELECT id as id, formid as formid, proposerid as proposerid,  **MIN(CAST(fieldid AS INTEGER)) AS fieldid**, response as response, remarks as remarks, listId as listId, isMarked as isMarked FROM responsemaster WHERE formid = 40066 AND proposerid = '7ca6533a-c5f0-43e2-9980-83f9ae2c7370201802230113550000'  GROUP BY fieldid

以上查询将在SQLite浏览器和大于Android 4.4.2版本的设备中成功执行..请问任何人可以帮助我如何解决该错误吗?

2 个答案:

答案 0 :(得分:0)

尝试此查询,它可能会替换聚合函数

return (CompletableFuture<Optional<T>>) (CompletableFuture<?>) EMPTY_FUT;

答案 1 :(得分:0)