select sum(a.duration_time) as quantity,b.dept_name,b.user_quantity from blade_employee_training_record_dept_user_quantity b LEFT JOIN (select * from blade_employee_training_record_detail where tenant_id=#{tenantId} <if test="startDate !=null and startDate !='' "> and end_training_date >= #{startDate} </if> <if test="startDate !=null and startDate !='' "> and end_training_date >= #{startDate} </if> ) a on a.dept_name=b.dept_name GROUP BY b.dept_name