热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

mysql查询到记录为1否则为0_count查询为空或者为0的时候,发现下面两种写法都是返回1,但是直接把sql放在mysql里面查询是0,难道是用了union导致的...

Stringcountstrsql语句请看下面;SqlcountSqlSqls.create(countstr);countSql.setCallback(Sqls.callb

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;



推荐阅读
author-avatar
klolo先生
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有