【mybatis plus】sum聚合函数的使用

// 获取合同包下所有合同的总金额之和
QueryWrapper<ContractMgt> contract_wrapper = new QueryWrapper<ContractMgt>();
contract_wrapper.eq("package_id", contractMgt.getPackageId());
contract_wrapper.select("isnull(sum(amount_total),0) as total ");
Map<String, Object> map = contractMgtService.getMap(contract_wrapper);
		
Double package_total_amount = Double.valueOf(String.valueOf(map.get("total")));

对应的sql语句:

-- contractMgt.getPackageId() -> 2
select isnull(sum(amount_total),0) as total
from contract_mgt
where package_id=2

你可能感兴趣的:(后端)