Hi,
I have the following table:
tblMeasurements
Date | value1| value2| ...|value24|
I need to find (and display) the maximum per day, i.e. the maximum number
among the value1...value24 in the same row (date).
I tried MAX(value1,....,value24) to no avail.
The examples I see on the net seem to find the max for all the entries of a
*specific* column. I want the max of a specific row. Can it be done and am i
looking at the right function ?
I know its a simple question but i cant seem to find the answer.
TIA
-steveSteve
Why not to store like this
CREATE TABLE #Test
(
[Id] Int not null primary key,
[Date] datetime not null,
Value int not null
)
SELECT MAX(Value),Date FROM #Test
GROUP BY Date
"Steve" <try@.this.com> wrote in message
news:xOz0e.19063$ZC6.78184@.wagner.videotron.net...
> Hi,
> I have the following table:
> tblMeasurements
> Date | value1| value2| ...|value24|
> I need to find (and display) the maximum per day, i.e. the maximum number
> among the value1...value24 in the same row (date).
> I tried MAX(value1,....,value24) to no avail.
> The examples I see on the net seem to find the max for all the entries of
a
> *specific* column. I want the max of a specific row. Can it be done and am
i
> looking at the right function ?
> I know its a simple question but i cant seem to find the answer.
> TIA
> -steve
>|||Try,
select
[Date]
max(value)
from
(
select
[date],
case n.colA
when 1 then value1
when 2 then value2
..
when 24 then value24
end as value
from
t
cross join
(
select 1
union all
select 2
union all
..
select 24
) as n(colA)
) as a
group by
[date]
go
AMB
"Steve" wrote:
> Hi,
> I have the following table:
> tblMeasurements
> Date | value1| value2| ...|value24|
> I need to find (and display) the maximum per day, i.e. the maximum number
> among the value1...value24 in the same row (date).
> I tried MAX(value1,....,value24) to no avail.
> The examples I see on the net seem to find the max for all the entries of
a
> *specific* column. I want the max of a specific row. Can it be done and am
i
> looking at the right function ?
> I know its a simple question but i cant seem to find the answer.
> TIA
> -steve
>
>
No comments:
Post a Comment