0

I have a table which contains two columns.

I want to find the maximum multiplication of these two columns and how many of them have this maxmimum value?

I have tried the max of the multiplication of two columns

But it didn't work. Any help will be appreciated.

Ellie
  • 1
  • 2
  • can you share what you have done. – Vidal Jun 12 '20 at 11:23
  • What do you mean with `max of the multiplication of two columns`? Is it the value contained inside the column? In this case, please provide an example to clarify your issue, otherwise it is very hard to understand what you need. – Dos Jun 12 '20 at 13:56

1 Answers1

0

You can use max():

select max(col1 * col2)
from t;

To find the number that match:

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

You can also use window functions:

select count(*)
from (select t.*, 
             rank() over (order by col1 * col2 desc) as seqnum
      from t
     ) t
where seqnum = 1;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786