Suppose I have a table "arrivals" which logs when an item arrives at a location. Each line corresponds to an arrival event.
arrivals
========
LocationId ItemId TimeStamp
------------------------------------------
a 1 2015-11-24 11:00 (item 1 arrived at 11:00 at location a)
a 2 2015-11-24 11:01 (item 2 arrived at 11:00 at location a)
b 1 2015-11-24 11:05 (item 1 left location a and arrived at b)
b 2 2015-11-24 11:06 (item 2 left location a and arrived at b)
Is there an SQL statement that can tell me which items where at location A at 11:03, possibly without bringing the SQL server to its knees?
(This would include all items that have arrived at location A before 11:03, and have not arrived anywhere else since then)
There are usually about 30 items per location at the same time, 100 different locations, and about 1000 arrivals per location per hour.
Are there any design choices that would simplify such queries, even if it means denormalising the database?
Currently I cannot even begin to imagine an sql command that could get me this information, without going through the entire table in a custom loop.