SELECT O.`order_id` orderId, O.`type` businessType, datediff(now(), min(pu.should_repay_time)) days, UF.`NAME` userName, UF.`MOBILE` mobile,CL.`NAME` channelName, DATE_FORMAT(min(pu.should_repay_time_forshow) ,'%Y-%m-%d') dateTime, pu.`remain_total` amount FROM pl_repayment_plan_user pu LEFT JOIN `pl_order` O ON pu.pl_order_id = O.id LEFT JOIN `userinfo` UF ON UF.ID = O.`userinfo_id` LEFT JOIN `channel` CL ON CL.`cid` = O.`channel_id` WHERE pu.bill_status = 2 AND (SELECT COUNT(1) FROM pl_repayment_plan_user d WHERE d.`bill_status` = 2 AND d.pl_order_id = pu.pl_order_id) = 1 GROUP BY pu.pl_order_id HAVING datediff(now(), min(pu.should_repay_time)) in(${dateRange})
group by 之后 ,select中如果有聚合函数,那结果集 每一个group 只有一个结果
有些情况需要 group by 后having来筛选
但是 有的时候需要在where中就要过滤掉,group by 之后会导致数据不准确