34,427
社区成员




-- 方法1
select a.*
from table1 a
where not exists(select 1
from table1 b
where b.name=a.name and b.gdtime>a.gdtime)
-- 方法2
select a.*
from table1 a
inner join
(select name,
max(gdtime) 'maxgdtime'
from table1
group by name) b on a.name=b.name and a.gdtime=b.maxgdtime
select * from tb as t where not exists(select 1 from tb where yhh=t.yhh and name=t. name and gdtime>t.gdtime)
select yhh,name,gdcs,gdsj1,gdtime
from tab a where not exists(select 1 from tab where yhh=a.yhh and gdtime>a.gdtime)
/* 1 用子查询 */
select yhh, name, gdcs, gdsj1, gdtime
from table1
where exists
(
select 1 from
(
select yhh, max(gdtime) as gdtime
from table1
group by yhh
) x
where x.yhh = table1.yhh
and x.gdtime = table1.gdtime
)
/* 2 用窗口函数 */
select * from
(
select yhh, name, gdcs, gdsj1, gdtime
, max(gdtime) over(partition by yhh) as gdtimeMax
from table1
) x
where gdtime = gdtimeMax