String countstr="sql语句请看下面";
Sql countSql = Sqls.create(countstr);
countSql.setCallback(Sqls.callback.longValue());
dao().execute(countSql);
Long totalRecordCount = countSql.getObject(Long.class);
Sql countSql = Sqls.create(countstr);
countSql.setCallback(Sqls.callback.longValue());
Long totalRecordCount = Daos.queryCount(dao(), countSql);
count查询为空或者为0的时候,发现上面两种写法都是返回1,但是直接把sql放在mysql里面查询是0,难道是用了union导致的??
select ifnull(count(*),0) from ( select * from (select c.code from T_crm_contract c where 1=1 and ( c.code like '%SHOKY20141201-00021#001%' or c.name like '%SHOKY20141201-00021#001%')
and c.status<>&#39;9&#39; and c.inner_flag<>&#39;1&#39; and ( ( (c.amount<>c.v_pay_amount and c.amount>0) OR (c.v_invoice_amount<>(c.v_pay_amount-c.v_rebate_amount)
and c.v_invoice_amount<>c.v_pay_amount) ) OR (c.v_deposit_plan_amount>0 and (c.v_deposit_plan_amount<>c.v_deposit_map_amount OR c.v_deposit_cantake_amount>0))
OR (c.v_advance_plan_amount>0 and (c.v_advance_plan_amount<>c.v_advance_map_amount OR c.v_advance_plan_amount<>c.v_advance_invoice_map_amount OR c.v_advance_cantake_amount>0))
OR (v_rebate_plan_amount>0 and (c.v_rebate_map_amount<>c.v_rebate_invoice_map_amount OR c.v_rebate_cantake_amount>0))
OR (c.process_status<>&#39;流程结束&#39; OR c.process_status is null OR c.archive_uid is null) ) ) t3
union
select * from (select t.ok_crm_code from T_crm_order t
where t.single_check is null and ( t.ok_crm_code like &#39;%SHOKY20141201-00021#001%&#39; or t.order_title like &#39;%SHOKY20141201-00021#001%&#39; or t.contract_code like &#39;%SHOKY20141201-00021#001%&#39;)
and t.status<>&#39;9&#39; and t.inner_flag<>&#39;1&#39; and ( ((t.amount<>t.v_pay_amount and t.amount>0) OR (t.v_invoice_amount<>(t.v_pay_amount-t.v_rebate_amount) and t.v_invoice_amount<>t.v_pay_amount) )
OR (t.process_status<>&#39;流程结束&#39; OR t.process_status is null OR t.archive_uid is null) ) ) t5 ) aa;