提问者:小点点

如何在SQL中求两列的最大乘法


我有一个包含两列的表。

我想找到这两列的最大乘法,有多少列有这个maxmimum值?

我试过两列相乘的最大值

但没起作用。 任何帮助都将不胜感激。


共1个答案

匿名用户

您可以使用max():

select max(col1 * col2)
from t;

要查找匹配的号码,请执行以下操作:

select count(*)
from t
where (t.col1 * t.col2) = (select max(t2.col1 * t2.col2) from t t2);

还可以使用窗口函数:

select count(*)
from (select t.*, 
             rank() over (order by col1 * col2 desc) as seqnum
      from t
     ) t
where seqnum = 1;