Table like
datetime a1 b1 x2 ...
07-01-2009 13:10 8 9 10
07-01-2009 13:11 8 8 2
07-01-2009 13:12 9 1 1
1 row per second for a whole day (=86400 rows); ~40 columns; all same format
I'm looking for a way to retrieve a max value and the time for a column to specify.
I'm looking for a way to retrive a max value and the according time for a column to specify within a timeframe.
Something like
Select top 1 time,a1 from table
where (datetime>=begin and datetime<end)
order by a1 desc
will work but I cannot use the column as a parameter.
A LINQ solution or a SP would be great.
Do I have to worry about performance when sorting a whole dataset to retrieve a max value? Maybe MAX function will be faster.
UPDATE
I tried to implement it the dynamic linq way, like Timothy (tvanfossen) suggested
Dim q2 = context.table _
.Where("t >= @0 AND t < @1", begin, end) _
.OrderBy("@0 desc", col) _
.Take(1) _
.Select(col)
BUT this returns the first value in the table.
This returns the first value in the time frame and not the max value. Looking at the SQL profiler I see that there is no ORDER clause.
Any idea?
UPDATE 2
For some reason the substitution value does not work in the orderby clause.
.OrderBY (col + " desc") works