-1
テーブル内に5つの列(a、b、c、d、e)が整数値であり、この表には100個の行があります。各列と列名の和はsql?つまりmax(sum(a)、sum(b)、sum(c)、sum(d)、sum(e))と列名sqlの列からの最大値の検索方法
テーブル内に5つの列(a、b、c、d、e)が整数値であり、この表には100個の行があります。各列と列名の和はsql?つまりmax(sum(a)、sum(b)、sum(c)、sum(d)、sum(e))と列名sqlの列からの最大値の検索方法
多くのデータベースでは、あなたはgreatest()
を使用することができます。
case
またはアンピボットと再凝集を使用することができ、この機能を持たないデータベースで
select greatest(sum(a), sum(b), sum(c), sum(d), sum(e))
from t;
:
select sum(val)
from ((select a as val, 'a' as which from t) union all
(select b as val, 'b' as which from t) union all
(select c as val, 'c' as which from t) union all
(select d as val, 'd' as which from t) union all
(select e as val, 'e' as which from t)
) abcde
group by which
order by sum(val) desc
fetch first 1 row only;
これはANSI構文です。一部のデータベースは、FETCH FIRST
の代わりにTOP
またはLIMIT
を使用します。
使用しているデータベースで質問にタグを付けます。 –
あなたの仕事を分かち合ってください。問題を解決しようとしましたか? "https://stackoverflow.com/help/how-to-ask" –
ゴードンの答えはいつもと同じです! – davejal