select TEMP.maxtime, TEMP.DEPTNAME
from (select d.f_create_time maxtime,
d.F_DEPT_NAME DEPTNAME,
row_number() over(partition by d.f_dept_id order by d.f_create_time desc) aa
from dpcrm.t_comp_record d
where d.f_type = 'COMPLAINT'
AND D.F_RECORD_SOURCE = 'FEEDBACK') temp
where temp.aa <= 1;
from (select d.f_create_time maxtime,
d.F_DEPT_NAME DEPTNAME,
row_number() over(partition by d.f_dept_id order by d.f_create_time desc) aa
from dpcrm.t_comp_record d
where d.f_type = 'COMPLAINT'
AND D.F_RECORD_SOURCE = 'FEEDBACK') temp
where temp.aa <= 1;