Insert into esua_epdc_custom.epdc_evaluate_dept(ID,DEPT_ID, DEPT_NAME, PARENT_DEPT_IDS, PARENT_DEPT_NAMES, ALL_DEPT_IDS, ALL_DEPT_NAMES, OFFICER_COUNT, DEL_FLAG, REVISION, CREATED_BY, CREATED_TIME, UPDATED_BY, UPDATED_TIME ) SELECT dept.gridId ID, dept.gridId DEPT_ID, dept.grid DEPT_NAME, dept.communityId PARENT_DEPT_IDS, dept.community PARENT_DEPT_NAMES, concat( dept.communityId, ',', dept.gridId ) ALL_DEPT_IDS, concat( dept.community, '-', dept.grid ) ALL_DEPT_NAMES, 0 OFFICER_COUNT, 0 DEL_FLAG, 1 REVISION, 'admin' CREATED_BY, now() CREATED_TIME, 'admin' UPDATED_BY, now() UPDATED_TIME FROM ( SELECT dis.`name` district, dis.id districtId, str.`name` street, str.id streetId, com.`name` community, com.id communityId, gri.`name` grid, gri.id gridId FROM sys_dept gri LEFT JOIN sys_dept com ON gri.pid = com.id LEFT JOIN sys_dept str ON com.pid = str.id LEFT JOIN sys_dept dis ON str.pid = dis.id WHERE gri.del_flag = '0' AND gri.type_key = 'street_party' AND gri.id NOT IN (SELECT id from esua_epdc_custom.epdc_evaluate_dept where DEL_FLAG = "0") ) dept