So, I've got a view that is admittedly not well-indexed and there's not much I can do about it.
The view has data that looks a bit like the one in this question, but my problem is essentially the opposite of theirs and I'm not sure their solution will work here, though a similar TVF or CTE is probably in the forecast.
My data looks like this at the moment:
CustomPollerAssignmentId DateTime Status
[Some Id B] 2013-11-18 08:54:00 IDLE
[Some Id A] 2013-11-18 08:54:00 DORMANT
[Some Id B] 2013-11-18 08:53:00 IDLE
[Some Id A] 2013-11-18 08:53:00 NOMINAL
Unlike the other question, I need to see that the status hasn't changed. The view comprises three separate tables. One with minute statistics, one with fifteen minute statistics (for between three and six months ago), and one for hourly statistics (for up to a year ago).
The goal here is to check which modems have been idle for at least the last 10 minutes. We've got about 1200 active modems, so this could be up to 12000 rows, which is why I'd prefer not to do it with C#, but I'm still kind of new to SQL and set-based thinking. I'm currently working with an instance of SQL Server 2012, but it's very new here and I'm not really experienced with the newer windowed functions since we were on 2008R2 until about a month ago.
To be honest, I'm not even sure where to begin here because my OOP background wants me to just grab the TOP 10 statuses for each and loop through. If all 10 == idle || dormant, add to the result set, but I know there's got to be a better way to do it in SQL. Can someone point me in the right direction?
EDIT
To try to clarify a bit:
I'm using T-SQL.
This isn't as simple as a WHERE NOT EXISTS clause.
Regardless of whether or not the status has changed, there should be an entry for the remote's status unless it has been deactivated. This means that it could have (idle, idle, idle, idle, idle, nominal, idle, idle, idle, idle) statuses for the last 10 minutes and that example is a case I would not want to include. The result set should include ONLY those remotes which have had statuses which are only idle or dormant for the last 10 minutes. If the last status is more than three months ago, it will only have one status for a fifteen minute interval.