SQL Where子句:在子句中的to列之间使用最大值

时间:2018-06-28 13:52:42

标签: sql max where

我有一个包含A列和B列的表。我试图选择A列和B列之间的每一行的最大值都大于10的所有行。

   A    B
   20   30
   5    9
   1    50

   Select A, B
   from table
   where max(a,b) > 10

   Desired Output:
   A    B
   20   30
   1    50

上面的代码不起作用,如何调整where子句?

2 个答案:

答案 0 :(得分:1)

当问题每次只涉及1行时,您如何/为什么在问题中使用“最大”一词?

select A, B
from table
where abs(a-b) > 10

向Zak授予我不知道的Abs功能

答案 1 :(得分:0)

您可以在where子句上执行iif:

  Select A, B
  from table
  where A > 10 OR B > 10

编辑:误解了这个问题!