TOP(n)
is SQL Server's propriatary counterpart to standard SQL's FETCH FIRST n ROWS
.
select count(*) as status_count, logid
from kioskstatuslog
where kioskid = :kioskid
and trunc(logdate) = trunc(sysdate)
group by logid
order by logid desc
fetch first row only;
As to
and trunc(logdate) = trunc(sysdate)
it is recommended to use
and logdate >= trunc(sysdate) and logdate < trunc(sysdate) + interval '1' day
instead, so the DBMS may use an index on that column if such exists. (Of course you could also have an index on trunc(logdate)
instead and keep the simpler expression.)