急救!在线等

无知者无谓 2010-12-06 04:37:42
很久没用数据库,现在碰到这么一个问题:
有一张表,表有3个字段,
id int;用来存放设备ID
value int;用来存放该设备状态
upd date;用来存放设备状态上报时间

现在我想获取指定设备最新的状态,请大家帮给一个sql语句可以吗?
感谢了
...全文
68 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
无知者无谓 2010-12-06
  • 打赏
  • 举报
回复
多谢!
还没用过exists呢,回头好好看一下。
rucypli 2010-12-06
  • 打赏
  • 举报
回复
select a.*
from tt a
where not exists(select 1 from tt where a.id=id and a.upd<upd)
and id=指定设备
wwwwb 2010-12-06
  • 打赏
  • 举报
回复
select a.* from tt a where not exists(select 1 from tt where a.id=id and a.upd<upd)

56,675

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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