mybatis中的查询语句
SELECT
contract_code as contractCode ,
sum( artificial_f ) as artificialFee ,
sum( mechanical_f ) as mechanicalFee
FROM
pay_list
<where>
contract_code like concat ('%' , #{contractCode} , '%')
</where>
当查询出来的结果为空时,postman返回
{
"msg": "操作成功",
"total": "1",
"code": "0",
"rows": [
null
]
}
rows中为null,正常返回为空时里面没有数据也没有null。
解决:
sum为聚合函数,聚合函数要分组进行使用。
SELECT
contract_code as contractCode ,
sum( artificial_f ) as artificialFee ,
sum( mechanical_f ) as mechanicalFee
FROM
pay_list
<where>
contract_code like concat ('%' , #{contractCode} , '%')
</where>
group by contract_code