I want to find the row number within the latest hour with the latest max value in a C# DataTable with the following columns: Name Score UnixTS. But can't seem to get the query right. I can easily get the row number for the latest max value from all values or as long as one hour has not yet passed. But as soon as one hour has passed the row number is null if there is an earlier max.
I have tried:
query = "UnixTS > " + fromUnixTS + " AND [Score] = MAX([Score])";
theRow = scoreTable.Select(query, "UnixTS DESC");
or
query = "[Score] = MAX([Score]) where UnixTS > fromUnixTS";
where fromUnixTS is now - 3600. Or even a SQL like query:
query = "SELECT * MAX([Score]) FROM scoreTable WHERE UnixTS > fromUnixTS ORDER BY UnixTS LIMIT 1":
or:
var theRow = scoreTable.AsEnumerable().Where(row => row.Field<int>("UnixTS") > fromUnixTS).Max(row => row.Field<int>("Score")).OrderByDescending<int>("UnixTX");
but no luck. OK I am not that experienced with C# but any help out there will be appreciated?
Hmmm, it seems that WHERE can't be used :-( But I have found a way forward:
query = "UnixTS > " + fromUnixTS";
theRow = scoreTable.Select(query, "Score DESC, UnixTS DESC");
Not the brightest way I must admit. Isn't there a clever way to use the MAX?