NutzCN Logo
问答 nutz dao 的 Cnd怎么复制?
发布于 2752天前 作者 qq_16dd5808 1621 次浏览 复制 上一个帖子 下一个帖子
标签:

我的代码是这样的,有两个sql语句公用一段条件,但是两个sql语句中有一个列冲突了

Dao dao = dbTools.getDao();

        Cnd cnd = Cnd.where("terminal_id", "=", did).and("year(day)", "=", year).and("month(day)", "=", month);

        mileage = dao.execute(Sqls.fetchDouble("select sum(kilometers) from biz_dev_kilometers $condition").setCondition(cnd)).getObject(Double.class);
        charge = dao.execute(Sqls.fetchDouble("select sum(charge) from biz_dev_kilometers $condition").setCondition(cnd)).getObject(Long.class);
        Cnd cnd1 = cnd;
        run_days = dao.count("biz_dev_kilometers", cnd1.and("kilometers", ">", 0));//月度运行天数
        Cnd cnd2 = cnd;
        stop_days = dao.count("biz_dev_kilometers", cnd2.and("kilometers", "=", 0));//月度停驶天数

最终导致stop_days计算错误,因为sql语句变成了

 AND kilometers>0 AND kilometers=0"

把上一个条件也给添加进去了。。。怎么破

1 回复

不支持复制

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