求条sql语句

xysoftzhk 2007-04-18 03:31:17
表结构
(
sn int,
id int,
time datetime
)
求 id=1、time最大的记录的sn
...全文
184 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hxd001_810 2007-04-18
  • 打赏
  • 举报
回复
select sn
from 表
where id=1 and time=(select max(time) from 表 where id=1 group by id)
chuifengde 2007-04-18
  • 打赏
  • 举报
回复
:)
select * from [表] where [time]=(select max([time]) from [表] where id=1 group by id)
chuifengde 2007-04-18
  • 打赏
  • 举报
回复
select id,max(b) sn from [表] where id=1 group by id
子陌红尘 2007-04-18
  • 打赏
  • 举报
回复
select
t.sn
from
表 t
where
t.id=1
and
not exists(select 1 from 表 where id=t.id and time>t.time)
子陌红尘 2007-04-18
  • 打赏
  • 举报
回复
select top 1 sn from 表 where id=1 order by time desc

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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