NutzCN Logo
问答 dao 列group by问题
发布于 2906天前 作者 qq_16dd5808 3156 次浏览 复制 上一个帖子 下一个帖子
标签:

已经提了
https://github.com/nutzam/nutz/issues/1180

现在这种用法也十分蛋疼。

Record fetch = dao.fetch("biz_dev_kilometers", Cnd.NEW().groupBy("day").asc("day"));

结果后台报错

org.nutz.dao.DaoException: !Nutz SQL Error: 'SELECT * FROM biz_dev_kilometers  GROUP BY day  ORDER BY day ASC   LIMIT 0, 1 '
PreparedStatement: 
'SELECT * FROM biz_dev_kilometers  GROUP BY day  ORDER BY day ASC   LIMIT 0, 1 '
CaseMessage=Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'fpiddb.biz_dev_kilometers.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

要是能过滤,是不是这个问题也能解决?

2 回复

能过滤的前提是预知有哪些列...

走自定义SQL吧

Record re = dao.execute(Sqls.fetchRecord("select count(age),xxx from yyy $cnd").setVar("cnd", Cnd.NEW().groupBy("day").asc("day"))).getObject(Record.class);

嗯,我想的不周到。一直觉得select后面肯定跟group by 的列。
目前我也是走的自定义sql

String s = "select day from biz_dev_kilometers GROUP BY day order by day limit 1";
        Sql sql = Sqls.fetchTimestamp(s);
        Date d = dao.execute(sql).getObject(Date.class);
        logger.debug("{}", TimeKit.format("yyyyMMdd", d));
添加回复
请先登陆
回到顶部