22,209
社区成员
发帖
与我相关
我的任务
分享
--如果只有两个字段
select chnalias , max(godate) godate from emp_trarel group by chnalias
select chnalias , max(godate) godate from emp_trarel where godate < getdate() group by chnalias
--如果有多个字段
select t.* from emp_trarel t where godate = (select max(godate) from emp_trarel where chnalias = t.chnalias)
select t.* from emp_trarel t where godate < getdate() and godate = (select max(godate) from emp_trarel where godate < getdate() and chnalias = t.chnalias)
select t.* from emp_trarel t where godate = (select max(godate) from emp_trarel where chnalias = t.chnalias)