SELECT a.*
FROM temptable a
WHERE (time IN
(SELECT max(time) AS time
FROM temptable b
WHERE a.sbname= b.sbname and day(time)=day(getdate())))
select sbname,[time],tempvalue from temptable t1 where id=
(select top 1 id from temptable t2 where t2.sbname=t1.sbname and datediff(day,[time],getdate())=0 order by [time] desc)