此SQL的优化以及如何将查询结果分两列展示

此SQL的优化以及如何将查询结果分两列展示

问题描述:

请问如何将此sql语句优化以及如何将查询结果分两列展示?

select COUNT(*) as "服务剩余总次数" from ACCT_PACKAGE_CUSTOMER  where USED_FLAG = 'N'and BR_UUID = '000000004e4c85a5014e4da389a4013d' and APC_STATUS = 'closeAccount'and APC_TYPE = 'servAndParts' UNION select COUNT(*) as "配件剩余总次数" from ACCT_PACKAGE_CUSTOMER  where USED_FLAG = 'N'and BR_UUID = '000000004e4c85a5014e4da389a4013d' and APC_STATUS = 'closeAccount'and APC_TYPE = 'service';

图片说明

图片说明

select COUNT(IF(APC_TYPE = 'servAndParts' ,1 ,null)) as "服务剩余总次数" ,COUNT(IF(APC_TYPE = 'service' ,1 ,null)) as "配件剩余总次数"  from ACCT_PACKAGE_CUSTOMER 
WHERE USED_FLAG = 'N'and BR_UUID = '000000004e4c85a5014e4da389a4013d' and APC_STATUS = 'closeAccount'

效率不敢保证

select count(if(status = 2,1,null)) ,count(if(status != 2,1,null))  from bill_log WHERE create_time between '2018-01-01' and '2018-10-01'

我的源代码 你可以仿照这个写一下,用于mysql