很久没用数据库,现在碰到这么一个问题:
有一张表,表有3个字段,
id int;用来存放设备ID
value int;用来存放该设备状态
upd date;用来存放设备状态上报时间现在我想获取指定设备最新的状态,请大家帮给一个sql语句可以吗?
感谢了
有一张表,表有3个字段,
id int;用来存放设备ID
value int;用来存放该设备状态
upd date;用来存放设备状态上报时间现在我想获取指定设备最新的状态,请大家帮给一个sql语句可以吗?
感谢了
from tt a
where not exists(select 1 from tt where a.id=id and a.upd<upd)
and id=指定设备
还没用过exists呢,回头好好看一下。