I would like to query a table having multiple rows, each with a timestamp
with data coming at ten minute intervals. I would like to find the beginning of any missing data, which is where there is not a timestamp
equaling the next ten minute interval, like this:
select a.[timestamp]
from [table] as a
where not exists (select 1
from [table] as b
where a.[id] = b.[id]
and b.[timestamp] = dateadd(mi, 10, a.[timestamp]))
order by a.[timestamp]
I have this so far, but I fail to see how to build the query to let me do the b.[timestamp] = dateadd(mi, 10, a.[timestamp]) in the query above:
Table tableAlias = null;
IList<DateTimeOffset> dateTimeOffsets = session.QueryOver(() => tableAlias)
.WithSubquery
.WhereNotExists(QueryOver.Of<Table>()
.Where(x => x.Id == tableAlias.Id)
.And(Restrictions.Eq(Projections.SqlFunction("addminutes",
NHibernateUtil.DateTimeOffset,
new[]
{
Projections.Property("Timestamp"),
Projections.Constant(10)
}),
<insert timestamp property again here>))
.Select(Projections.Constant(1)))
.Select(x => x.Timestamp)
.List<DateTimeOffset>();
I can not get my head round the restriction on the sqlfuntion part - Nhibernate
just won't let me do the comparison of the sqlfunction and my timestamp.
I hope I am on the right track with the code above, but please correct me if I'm totally off with my attempt at solving this...
Kind regards