select p.UNIT_NAME as 'CUSTOMER_NAME',p.DEPT_NAME as 'DEPART_NAME',p.DEPT_NO as 'DEPART_NO',
d.BUSINESS_PRIMARY_TYPE as 'BUSINESS_PRIMARY',d.BUSINESS_SECOND_TYPE as 'BUSINESS_SECOND',d.BUSINESS_THIRD_TYPE as 'BUSINESS_THIRD',
p.EMP_LABEL as 'LABEL',d.LINE_TYPE as 'BUSINESS_TYPE',d.BU_BELONG as 'BU_BELONG',c1.EMP_NATRUE as 'EMP_TYPE',
e.EMP_NAME as 'EMP_NAME',e.EMP_SEX as 'EMP_SEX',DATE_FORMAT(e.EMP_BIRTHDAY ,"%Y-%m-%d") as 'EMP_BIRTH_DATE',e.EMP_AGE as 'EMP_AGE',e.EMP_IDCARD as 'EMP_IDCARD',
e.EMP_PHONE as 'EMP_PHONE',c1.FILE_PROVINCE as 'EMP_PROVINCE',c1.FILE_CITY as 'EMP_CITY',c1.FILE_TOWN as 'EMP_TOWN',
p.SOCIAL_PROVINCE as 'SOCIAL_PROVINCE',p.SOCIAL_CITY as 'SOCIAL_CITY',p.SOCIAL_TOWN as 'SOCIAL_TOWN',c1.APPLY_NO as 'CONTRACT_APPLY_NO',
c1.CONTRACT_START as 'CONTRACT_START',c1.CONTRACT_END as 'CONTRACT_END',c1.CONTRACT_NAME as 'CONTRACT_TYPE',c1.CONTRACT_SUB_NAME as 'BUSINESS_DETAIL',
c1.SITUATION as 'SIGN_TYPE',c1.CONTRACT_TYPE as 'SIGN_TERM',
c1.CONTRACT_PARTY as 'CONTRACT_PARTY_A',c1.POST as 'CONTRACT_POST',c1.WORKING_HOURS as 'CONTRACT_TASK_TIME',
c1.CONTRACT_NO as 'CONTRACT_CODE',c1.CREATE_NAME as 'CONTRACT_CREATER',c1.CREATE_TIME as 'CONTRACT_CREATE_TIME',
d.id as "SETTLE_DOMAIN"
select c1.SUBJECT_UNIT as 'CUSTOMER_NAME',c1.SUBJECT_DEPART as 'DEPART_NAME',c1.DEPT_NO as 'DEPART_NO',
d.BUSINESS_PRIMARY_TYPE as 'BUSINESS_PRIMARY',d.BUSINESS_SECOND_TYPE as 'BUSINESS_SECOND',d.BUSINESS_THIRD_TYPE as 'BUSINESS_THIRD',
p.EMP_LABEL as 'LABEL',d.LINE_TYPE as 'BUSINESS_TYPE',d.BU_BELONG as 'BU_BELONG',c1.EMP_NATRUE as 'EMP_TYPE',
c1.EMP_NAME as 'EMP_NAME',e.EMP_SEX as 'EMP_SEX',DATE_FORMAT(e.EMP_BIRTHDAY ,"%Y-%m-%d") as 'EMP_BIRTH_DATE',e.EMP_AGE as 'EMP_AGE',c1.EMP_IDCARD as 'EMP_IDCARD',
e.EMP_PHONE as 'EMP_PHONE',c1.FILE_PROVINCE as 'EMP_PROVINCE',c1.FILE_CITY as 'EMP_CITY',c1.FILE_TOWN as 'EMP_TOWN',
p.SOCIAL_PROVINCE as 'SOCIAL_PROVINCE',p.SOCIAL_CITY as 'SOCIAL_CITY',p.SOCIAL_TOWN as 'SOCIAL_TOWN',c1.APPLY_NO as 'CONTRACT_APPLY_NO',
c1.CONTRACT_START as 'CONTRACT_START',c1.CONTRACT_END as 'CONTRACT_END',c1.CONTRACT_NAME as 'CONTRACT_TYPE',c1.CONTRACT_SUB_NAME as 'BUSINESS_DETAIL',
c1.SITUATION as 'SIGN_TYPE',c1.CONTRACT_TYPE as 'SIGN_TERM',
c1.CONTRACT_PARTY as 'CONTRACT_PARTY_A',c1.POST as 'CONTRACT_POST',c1.WORKING_HOURS as 'CONTRACT_TASK_TIME',
c1.CONTRACT_NO as 'CONTRACT_CODE',c1.CREATE_NAME as 'CONTRACT_CREATER',c1.CREATE_TIME as 'CONTRACT_CREATE_TIME',
d.id as "SETTLE_DOMAIN"
from
(select MAX(c.CREATE_TIME),c.id,c.EMP_IDCARD,c.DEPT_NO from t_employee_contract_info c WHERE c.IN_USE = 0 and c.DELETE_FLAG='0'
GROUP BY c.DEPT_NO,c.EMP_IDCARD) t
LEFT JOIN t_employee_info e on e.EMP_IDCARD=t.EMP_IDCARD
LEFT JOIN t_employee_project p on p.EMP_IDCARD=t.EMP_IDCARD and p.DEPT_NO=t.DEPT_NO
LEFT JOIN t_settle_domain d on d.DEPART_NO=t.DEPT_NO
INNER JOIN t_employee_contract_info c1 on c1.id=t.id GROUP BY t.DEPT_NO,t.EMP_IDCARD
(select MAX(c.CREATE_TIME),c.id,c.EMP_IDCARD,c.DEPT_NO from t_employee_contract_info c WHERE c.IN_USE = 0 and c.DELETE_FLAG='0'
GROUP BY c.DEPT_NO,c.EMP_IDCARD) t
LEFT JOIN t_employee_info e on e.EMP_IDCARD=t.EMP_IDCARD
LEFT JOIN t_employee_project p on p.EMP_IDCARD=t.EMP_IDCARD and p.DEPT_NO=t.DEPT_NO
LEFT JOIN t_settle_domain d on d.DEPART_NO=t.DEPT_NO
INNER JOIN t_employee_contract_info c1 on c1.id=t.id GROUP BY t.DEPT_NO,t.EMP_IDCARD