分组取最大值
select * from 表 where (序号,名称) in (select max(序号),名称 from 表 group by 名称)
select a.pk_frmins, a.port_id, to_char(wmsys.wm_concat(u.user_name))
from wfm_task a, cp_user u
where a.port_id in (select max(w.port_id)
from wfm_task w
where w.pk_frmins = a.pk_frmins
and w.state = 'State_End')
and a.pk_frmins in (pks)
and a.pk_owner = u.cuserid
group by a.pk_frmins, a.port_id
注意:max的字段只能是number类型字段,如果是date类型的,会提示错误。date类型用上面的row_number()来做就可以了。
网友评论