このテーブルがあるとします
マイテーブル
ID NumValue1 NumValue2 NumValue3 NumValue4 NumValue5
1 12.17 23.97 null 0.07 null LINQ構文
を使用して、この単一の行から23.97
である最大値を取得する方法は?
SQL (MS SQL) では、次のように記述できます。
SELECT MaxNum = case
when MyTable.NumValue1 is not null and
(MyTable.NumValue1 >= MyTable.NumValue2 or MyTable.NumValue2 is null) and
(MyTable.NumValue1 >= MyTable.NumValue3 or MyTable.NumValue3 is null) and
(MyTable.NumValue1 >= MyTable.NumValue4 or MyTable.NumValue4 is null) and
(MyTable.NumValue1 >= MyTable.NumValue5 or MyTable.NumValue5 is null)
then MyTable.NumValue1
when MyTable.NumValue2 is not null and
(MyTable.NumValue2 >= MyTable.NumValue1 or MyTable.NumValue1 is null) and
(MyTable.NumValue2 >= MyTable.NumValue3 or MyTable.NumValue3 is null) and
(MyTable.NumValue2 >= MyTable.NumValue4 or MyTable.NumValue4 is null) and
(MyTable.NumValue2 >= MyTable.NumValue5 or MyTable.NumValue5 is null)
then MyTable.NumValue2
when MyTable.NumValue3 is not null and
(MyTable.NumValue3 >= MyTable.NumValue1 or MyTable.NumValue1 is null) and
(MyTable.NumValue3 >= MyTable.NumValue2 or MyTable.NumValue2 is null) and
(MyTable.NumValue3 >= MyTable.NumValue4 or MyTable.NumValue4 is null) and
(MyTable.NumValue3 >= MyTable.NumValue5 or MyTable.NumValue5 is null)
then MyTable.NumValue3
when MyTable.NumValue4 is not null and
(MyTable.NumValue4 >= MyTable.NumValue1 or MyTable.NumValue1 is null) and
(MyTable.NumValue4 >= MyTable.NumValue2 or MyTable.NumValue2 is null) and
(MyTable.NumValue4 >= MyTable.NumValue3 or MyTable.NumValue3 is null) and
(MyTable.NumValue4 >= MyTable.NumValue5 or MyTable.NumValue5 is null)
then MyTable.NumValue4
when MyTable.NumValue5 is not null and
(MyTable.NumValue5 >= MyTable.NumValue1 or MyTable.NumValue1 is null) and
(MyTable.NumValue5 >= MyTable.NumValue2 or MyTable.NumValue2 is null) and
(MyTable.NumValue5 >= MyTable.NumValue3 or MyTable.NumValue3 is null) and
(MyTable.NumValue5 >= MyTable.NumValue4 or MyTable.NumValue4 is null)
then MyTable.NumValue5
else null
end
FROM MyTable WHERE MyTable.ID=1;
ありがとうございました。