如何查得最大行

you_tube 2008-07-28 05:10:29

有表tab1,字段(id,time1,time2)

080700080 2008-07-28 00:00:00.000 2008-07-31 00:00:00.000
080700080 2008-07-28 00:00:00.000 2008-08-28 00:00:00.000
080700081 2008-07-28 00:00:00.000 2008-07-31 00:00:00.000
080700080 2008-07-28 00:00:00.000 2008-08-11 00:00:00.000
080700081 2008-07-28 00:00:00.000 2008-09-31 00:00:00.000

要取得结果:
080700080 2008-07-28 00:00:00.000 2008-08-28 00:00:00.000
080700081 2008-07-28 00:00:00.000 2008-09-31 00:00:00.000

如何查询???
...全文
87 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
-晴天 2008-07-28
  • 打赏
  • 举报
回复
select id,time1,max(time2) from tab1 group by id,time1
ojuju10 2008-07-28
  • 打赏
  • 举报
回复
select * from tab1 t
where t.time2 in (select max(time2) from tab1 where id= t.id and time1 =t.time1 )
hery2002 2008-07-28
  • 打赏
  • 举报
回复
select * from tab1 t
where not exists(select 1 from tab1 where id= t.id and time1 =t.time1 and time2>t.time1)

27,582

社区成员

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

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