NutzCN Logo
问答 nutz groupby怎么用?
发布于 2701天前 作者 qq_412bd180 2529 次浏览 复制 上一个帖子 下一个帖子
标签:
@At
	@Ok("json")
	//String sql="select distinct type from t_dict";
	public NutMap getFaultTypes() {
		List<FaultDict> list = dao.query(FaultDict.class, Cnd.where("isDeleted", "=", false).groupBy("type"));
		System.out.println();
		return NutMap.NEW().addv("typeList", list);
		
		/*Sql sql = Sqls.create("select distinct type from t_dict");
		dao.execute(sql);
		System.out.println("sql.getList(String.class):"+sql.getList(String.class));
		return NutMap.NEW().addv("typeList", sql.getList(String.class));*/
	}

提示语句不对

6 回复

这样写

List<Record> cmsList = dao.query("t_dict", Cnd.where("isDeleted","=","false").groupBy("type"), null, "type");

报错

想达到这样的效果

select type from t_dict group by type;

没有聚合函数

这样写OK

@At
	@Ok("json")
	//String sql="select distinct type from t_dict";
	public NutMap getFaultTypes() {
		FieldFilter ff = FieldFilter.create(FaultDict.class, "^type$");
		List<FaultDict> list = Daos.ext(dao, ff).query(FaultDict.class,Cnd.where("isDeleted","=",false).groupBy("type"));
		return NutMap.NEW().addv("typeList", list);

我要是需要Id来排序呢

@At
	@Ok("json")
	//String sql="select distinct type from t_dict";
	public NutMap getFaultTypes() {
		FieldFilter ff = FieldFilter.create(FaultDict.class, "^type|id$");
		List<FaultDict> list = Daos.ext(dao, ff).query(FaultDict.class,Cnd.where("isDeleted","=",false).groupBy("type").asc("id"));
		return NutMap.NEW().addv("typeList", list);

这么写报错

select的字段里面要有聚合函数,例如count,sum

添加回复
请先登陆
回到顶部