NutzCN Logo
问答 sql拼接,另能不能同时返回count数据条数
发布于 2121天前 作者 wx_nvu0j53rdpc0ebqbi0kc 1884 次浏览 复制 上一个帖子 下一个帖子
标签:

sql,多了一个where 怎么办?

 Cnd cnd = Cnd.NEW();
        and(cnd,"a.year","=",yearString);
        and(cnd,"a.allotId","=",allotId);
        and(cnd,"b.PARENT_CODE","=",region);//TODO:前一个region是街道id,后一个是用户所属区id,要改 对象region=字典表街道id parentid=user.regionid
//        List<DfjgProjectDO> list = dao.query(DfjgProjectDO.class,cnd,pager);
        Sql sql = Sqls.create("select a.* from DFJG_PROJECT a,dc_region b where a.BSHA0008 = b.id $cnd");
        sql.setCallback(Sqls.callback.entities());
        sql.setEntity(dao.getEntity(DfjgProjectDO.class));
        sql.setVar("cnd",cnd);
        dao.execute(sql);
15 回复

Daos.queryCount(sql)

@wendal 生成的sql多了一个where 怎么办

@wendal 生成记录数的应该是这个吧Daos.queryCount(dao,sql);不然报错

@wendal 多了一个where咋办啊 这是关键。:)

先count然后查询

select a.* from DFJG_PROJECT a,dc_region b where a.BSHA0008 = b.id and 。。。。

现在是select a.* from DFJG_PROJECT a,dc_region b where a.BSHA0008 = b.id where 。。。。。

多了一个where

@wendal 大佬 还在伐 怎么把后面where去掉啊

那这个跟count没关系的啊, 另外一个问题咯

cnd.where().setTop(false); // 这样就没有where了

@wendal 还是有问题哎

sql又变成:select a.* from DFJG_PROJECT a,dc_region b where a.BSHA0008 = b.id (a.year='2018' and ....)
少了and

 Cnd cnd = Cnd.NEW();
        cnd.where().setTop(false); // 这样就没有where了
        and(cnd,"a.year","=",yearString);
        and(cnd,"a.allotId","=",allotId);
        and(cnd,"b.PARENT_CODE","=",region);
//        List<DfjgProjectDO> list = dao.query(DfjgProjectDO.class,cnd,pager);
        Sql sql = Sqls.create("select a.* from DFJG_PROJECT a,dc_region b where a.BSHA0008 = b.id $cnd");
        sql.setCallback(Sqls.callback.entities());
        sql.setEntity(dao.getEntity(DfjgProjectDO.class));
        sql.setVar("cnd",cnd);
        Daos.queryCount(dao,sql);
        dao.execute(sql);

那加个and不就好了

Sql sql = Sqls.create("select a.* from DFJG_PROJECT a,dc_region b where a.BSHA0008 = b.id and $cnd"); // 加个and就合法啦

不是感觉丑嘛。。。

额(︶︿︶)=凸

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