请问一条SQL语句的写法.谢大家.

hzh_wen_x 2006-11-10 04:49:36
ID XM SJ
1 张三 2006
2 张三 2007
3 李四 2005
4 李四 2006
5 王五 2006

我想取得的结果是每个人最近的那一条记录

ID XM SJ
2 张三 2007
4 李四 2006
5 王五 2006

有办法吗?
...全文
146 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
hzh_wen_x 2006-11-10
  • 打赏
  • 举报
回复
hellowork(一两清风) 对不起,结贴的时候点快了.
dawugui 2006-11-10
  • 打赏
  • 举报
回复
select a.* from tb a,
(select xm,max(sj) as sj from tb group by name) b
where a.xm = b.xm and a.sj = b.sj
xiao_deng 2006-11-10
  • 打赏
  • 举报
回复
过来看星星

hellowork 2006-11-10
  • 打赏
  • 举报
回复
select * from table as t
where not exists(select 1 from table where XM = t.XM and id > t.id)

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧